The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

floor - floor function

 SYNOPSIS



#include <math.h>

double floor(double x);

 DESCRIPTION

The floor() function computes the largest integral value not greater than x.

An application wishing to check for error situations should set errno to 0 before calling floor(). If errno is non-zero on return, or the return value is NaN, an error has occurred.

 RETURN VALUE

Upon successful completion, floor() returns the largest integral value not greater than x, expressed as a double.

If x is NaN, NaN is returned and errno may be set to [EDOM].

If the correct value would cause overflow, -HUGE_VAL is returned and errno is set to [ERANGE].

If x is ±Inf or ±0, the value of x is returned.

 ERRORS

The floor() function will fail if:
[ERANGE]
The result would cause an overflow.

The floor() function may fail if:

[EDOM]
The value of x is NaN.

No other errors will occur.

 EXAMPLES

None.

 APPLICATION USAGE

The integral value returned by floor() as a double might not be expressible as an int or long int. The return value should be tested before assigning it to an integer type to avoid the undefined results of an integer overflow.

The floor() function can only overflow when the floating point representation has DBL_MANT_DIG > DBL_MAX_EXP.

 FUTURE DIRECTIONS

None.

 SEE ALSO

ceil(), isnan(), <math.h>.

DERIVATION

Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]