FLOOR(3M) Silicon Graphics FLOOR(3M) NAME floor, ffloor, floorf, ceil, fceil, ceilf, fmod, fmodf, fabs, fabsf, rint, trunc, ftrunc, truncf - floor, ceiling, remainder, absolute value, nearest integer, and truncation functions SYNOPSIS #include double floor (double x); float ffloor (float x); float floorf (float x); double ceil (double x); float fceil (float x); float ceilf (float x); double trunc (double x); float ftrunc (float x); float truncf (float x); double fmod (double x, double y); float fmodf (float x, float y); double fabs (double x); float fabsf (float x); double rint(double x); DESCRIPTION The fmod, fabs, and trunc functions listed above, as well as the single- precision versions of the remaining functions, are only available in the standard math library, -lm. The floor functions return the largest integer not greater than x. The argument x is double for floor, and float for ffloor and its ANSI-named equivalent floorf. The ceil functions return the smallest integer not less than x. The argument x is double for ceil, and float for fceil and its ANSI-named equivalent ceilf. The trunc functions return the integer (represented as a floating-point number) of x with the fractional bits truncated. The argument x is double for trunc, and float for ftrunc. fabs returns the absolute value of the double x, |x|. It also has a counterpart of type float, namely fabsf. rint returns the integer (represented as a double precision number) nearest its double argument x in the direction of the prevailing rounding mode. rint has no counterpart which accepts an argument of type float. Page 1 Release 3.10 June 1992 FLOOR(3M) Silicon Graphics FLOOR(3M) fmod returns the floating-point remainder of the division of its double arguments x by y. It returns a number f with the same sign as x, such that x = iy + f for some integer i, and |f| < |y|. Hence both the invocations fmod(2.5,1.0) fmod(2.5,-1.0) yield 0.5, while the two invocations fmod(-2.5,1.0) fmod(-2.5,-1.0) yield -0.5. fmodf is the counterpart of fmod which accepts and returns values of type float. DIAGNOSTICS In the diagnostics below, functions in the standard math library libm.a, are referred to as -lm versions, and those in the the BSD math library libm43.a, are referred to as -lm43 versions. The -lm versions always return the default Quiet NaN and set errno to EDOM when a NaN is used as an argument. A NaN argument usually causes the -lm43 versions to return the same argument. The -lm43 versions never set errno. The value of HUGE_VAL is IEEE Infinity. If y (and, possibly, x) are zero, or if x is +/-HUGE_VAL, the fmod functions return a quiet NaN, and set errno to EDOM. If the quantity x/y would overflow, the fmod functions may return zero, without setting errno. A version of the double-precision fabs function exists in the C library as well. The C library version may not behave correctly when the input is NaN. NOTES In the default rounding mode, to nearest, rint(x) is the integer nearest x with the additional stipulation that if |rint(x)-x|=1/2 then rint(x) is even. Other rounding modes can make rint act like floor, or like ceil, or round towards zero. Another way to obtain an integer near x is to declare (in C) double x; int k; k = x; The C compilers round x towards zero to get the integer k. Also note that, if x is larger than k can accommodate, the value of k and the presence or absence of an integer overflow are hard to detect. SEE ALSO abs(3C), math(3M) Page 2 Release 3.10 June 1992