The floor subroutine, floorl subroutine, ceil subroutine, ceill subroutine, nearest subroutine, trunc subroutine, and rint subroutine round floating-point numbers to floating-point integer values.
The itrunc subroutine and uitrunc subroutine round floating-point numbers to signed and unsigned integers, respectively.
The fmod subroutine and fmodl subroutine compute the modulo remainder. The fabs subroutine and fabsl subroutine compute the floating-point absolute value.
IEEE Math Library
(libm.a)
or System V Math Library (libmsaa.a)
Standard C Library (libc.a) (separate syntax follows)
#include <math.h>
double floor ( x)
double x;
long double floorl (x) long double x;
double ceil (x) double x;
long double ceill (x) long double x;
double nearest (x) double x;
double trunc (x) double x;
double fmod (x, y)
double x, y;
long double fmodl (x) long double x, y;
double fabs (x) double x;
long double fabsl (x) long double x;
#include <stdlib.h> #include <limits.h>
double rint (x) double x;
int itrunc (x) double x;
unsigned int uitrunc (x) double x;
The floor subroutine and floorl subroutines return the largest floating-point integer value not greater than the x parameter.
The ceil subroutine and ceill subroutine return the smallest floating-point integer value not less than the x parameter.
The nearest subroutine returns the nearest floating-point integer value to the x parameter. If x lies exactly halfway between the two nearest floating-point integer values, an even floating-point integer is returned.
The trunc subroutine returns the nearest floating-point integer value to the x parameter in the direction of 0. This is equivalent to truncating off the fraction bits of the x parameter.
The rint subroutine returns one of the two nearest floating-point integer values to the x parameter. To determine which integer is returned, use the current floating-point rounding mode as described in the IEEE Standard for Binary Floating-Point Arithmetic.
If the current rounding mode is round toward -INF, rint(x) is identical to floor(x).
If the current rounding mode is round toward +INF, rint(x) is identical to ceil(x).
If the current rounding mode is round to nearest, rint(x) is identical to nearest(x).
If the current rounding mode is round toward zero, rint(x) is identical to trunc(x).
Note: The default floating-point rounding mode is round to nearest. All C main programs begin with the rounding mode set to round to nearest.
The itrunc subroutine returns the nearest signed integer to the x parameter in the direction of 0. This is equivalent to truncating the fraction bits from the x parameter and then converting x to a signed integer.
The uitrunc subroutine returns the nearest unsigned integer to the x parameter in the direction of 0. This action is equivalent to truncating off the fraction bits of the x parameter and then converting x to an unsigned integer.
The fmod subroutine and fmodl subroutine compute the modulo floating-point remainder of x/y. The fmod and fmodl subroutines return the value x-iy for a i such that if y is nonzero, the result has the same sign as x and magnitude less than the magnitude of y.
The fabs and fabsl subroutines return the absolute value of x, |x|.
Note: Compile any routine that uses subroutines from the libm.a library with the -lm flag. To compile the floor.c file, for example, enter:
x | Specifies a double-precision floating-point value. For the floorl, ceill, fmodl, and fabsl subroutines, specifies a long double-precision floating-point value. |
y | Specifies a double-precision floating-point value. For the floorl, ceill, fmodl, and fabsl subroutines, specifies some long double-precision floating-point value. |
The itrunc and uitrunc subroutines return the INT_MAX value if x is greater than or equal to the INT_MAX value and the INT_MIN value if x is equal to or less than the INT_MIN value. The itrunc subroutine returns the INT_MIN value if x is a Quiet NaN(not-a-number) or Silent NaN. The uitrunc subroutine returns 0 if x is a Quiet NaN or Silent NaN. (The INT_MAX and INT_MIN values are defined in the limits.h file.) The uitrunc subroutine INT_MAX if x is greater than INT_MAX and 0 if x is less than or equal 0.0
The fmod and fmodl subroutines for (x/0) return a Quiet NaN and set the errno global variable to a EDOM value.
These subroutines are part of Base Operating System (BOS) Runtime.
The itrunc, uitrunc, trunc, nearest, and rint subroutines are not part of the ANSI C Library.
float.h | Contains the ANSI C FLT_ROUNDS macro. |
The fp_read_rnd or fp_swap_rnd (fp_read_rnd or fp_swap_rnd Subroutine) subroutine.
Subroutines Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.
128-Bit long double Floating-Point Format in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.