The floor subroutine, floorf subroutine, floorl subroutine, nearest subroutine, and trunc 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.

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;`

float floorf (x) float x;

long double floorl (x) long double x;

double nearest (x) double x;

double trunc (x) double x;

Standard C Library (libc.a)

#include <stdlib.h> #include <limits.h>

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.

An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these subroutines. Upon return, if errno is nonzero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is nonzero, an error has occurred.

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.

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.

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:

cc floor.c -lm

The itrunc, uitrunc, trunc, and nearest subroutines are not part of the ANSI C Library.

x | Specifies a double-precision floating-point value. For the floorl subroutine, specifies a long double-precision floating-point value. |

y | Specifies a double-precision floating-point value. For the floorl subroutine, specifies some long double-precision floating-point value. |

Upon successful completion, the floor, floorf, and floorl subroutine returns the largest integral value not greater than x, expressed as a double, float, or long double, as appropriate for the return type of the function.

If x is NaN, a NaN is returned.

If x is ±0 or ±Inf, x is returned.

If the correct value would cause overflow, a range error occurs and the floor, floorf and floorl subroutines return the value of the macro -HUGE_VAL, -HUGE_VALF and -HUGE_VALL, respectively.

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

float.h | Contains the ANSI C FLT_ROUNDS macro. |

feclearexcept Subroutine, fetestexcept Subroutine, and class, _class, finite, isnan, or unordered Subroutines.

The fp_read_rnd or fp_swap_rnd (fp_read_rnd or fp_swap_rnd Subroutine) subroutine.

Subroutines Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

128-Bit long double Floating-Point Format in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

math.h in AIX 5L Version 5.2 Files Reference.