Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

isnan(3)

ieee(3)

math(3)

floor(3)  —  Subroutines

Digital

NAME

floor, ceil, rint, fmod, fabs − Rounds floating-point numbers to floating-point integers, or computes the Modulo Remainder and floating-point absolute value functions

LIBRARY

Math Library (libm.a)
Standard C Library (libc.a)

SYNOPSIS

#include <math.h>
double floor (
  double x);

float ffloor (
  float x);

double ceil (
  double x);

float fceil (
  float x);

double trunc (
  double x);

float ftrunc (
  float x);

double fmod (
  double x,
  double y);

double fabs (
  double x);

double rint (
  double x);

PARAMETERS

xSpecifies some double value. 

ySpecifies some double value. 

DESCRIPTION

The floor() and ffloor() functions return the largest floating-point integer not greater than the x parameter. 

The ceil() and fceil() functions return the smallest floating-point integer not less than the x parameter. 

The trunc() and ftrunc() functions return the integer (represented as a floating-point number) of x with the fractional bits truncated for double and float data types respectively. 

The rint() function returns one of the two nearest floating point integers to the x parameter. Which integer is returned is determined by 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 -infinity, then rint(x) is identical to floor(x).  If the current rounding mode is round toward +infinity, then rint(x) is identical to ceil(x).

The fmod() function computes the modulo floating-point remainder of x/y. The fmod() function returns the value x - (i∗y) for some 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() function returns the absolute value of x, a floating-point number.

NOTES

AES Support Level: Full use (floor(), ceil(), fmod(), fabs())

The default floating-point rounding mode is round to nearest.  All C main programs begin with the rounding mode set to round to nearest. 

In the 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. 

The routine fabs is in libc.a rather than libm.a. 

RETURN VALUES

Upon successful completion, the floor() function returns the largest integral value not greater than x.  If x is NaN, NaN is returned and errno may be set to [EDOM].  Otherwise, −HUGE_VAL is returned.

Upon successful completion, the ceil() function returns the smallest integral value not less than x.  If x is NaN, NaN is returned.  Otherwise, either HUGE_VAL or NaN is returned. 

Upon successful completion, the fmod() function returns the remainder of the division of x by y.  If x or y is NaN, NaN is returned.  If y is 0 (zero), the fmod() function returns NaN and sets errno to [EDOM]. 

Upon successful completion, the fabs() function returns the absolute value of x.  If x is NaN, NaN is returned.  Otherwise, either errno is set to indicate the error or NaN is returned. 

ERRORS

If the floor() function fails, errno may be set to one of the following values:

[ERANGE]The result would cause an overflow. 

[EDOM]The value of x is NaN. 

If the ceil() function fails, errno may be set to one of the following values:

[ERANGE]The result would cause an overflow. 

[EDOM]The value of x is NaN. 

If the fmod() function fails, errno may be set to the following value:

[EDOM]The y argument is zero or one of the arguments is NaN. 

If the fabs() function fails, errno may be set to the following value:

[EDOM]The value of x is NaN. 

RELATED INFORMATION

Functions: isnan(3) ieee(3) math(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026