HP-UX Floating-Point Guide

66 Chapter 2
Floating-Point Principles and the IEEE Standard for Binary Floating-Point Arithmetic
Floating-Point Operations
Integer to Double-Precision or
Single-Precision These conversions are exact except
for conversions of 32-bit integer
values greater than 2
24
1 to
single-precision, or of 64-bit integer
values greater than 2
53
1 to
double-precision, which may generate
an inexact result exception.
The Remainder Operation
The remainder operation is an exact modulo function. When y is not
equal to zero, the remainder r = remainder(x, y) is defined as
r = x - y * n
where n is the integer nearest the exact value x/y. When |n x/y| = 1/2,
n is even. If r is zero, its sign is that of x.
Two examples:
The integer closest to the exact value 1.6/2.0 is 1. So the remainder of
1.6 and 2.0 is 1.6 (2.0 * 1), or 0.4.
The integer closest to the exact value 5.0/2.0 is 2 (the exact value is
halfway between 2 and 3, so n is even). So the remainder of 5.0 and
2.0 is 5.0 (2.0 * 2), or 1.
The result of the remainder operation is not affected by the rounding
mode. (The result is always exact, so rounding is not a factor.)
The C math library remainder function implements the IEEE
remainder operation.