Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

abs(3)

ieee(3m)

math(3m)

floor(3m)  —  RISC

Name

floor, ffloor, fabs, ceil, ceil, trunc, ftrunc, fmod, rint − floor, absolute value, ceiling, truncation, floating point remainder and round-to-nearest functions

Syntax

#include <math.h>

double floor(x)
double x;

float ffloor(x)
float x;

double ceil(x)
double x;

float fceil(x)
float x;

double trunc(x)
double x;

float ftrunc(x)
float x;

double fabs(x)
double x;

double fmod (x, y)
double x, y;

double rint(x)
double x;

Description

The floor and ffloor routines return the largest integer which is not greater than x for double and float data types, respectively.

The ceil and fceil routines return the smallest integer which is not less than x for double and float data types, respectively.

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

The fabs routine returns the absolute value |x|.

The fmod routine returns the floating point remainder of the division of x by y: zero if y is zero or if x/y would overflow; otherwise the number f with the same sign as x, such that x = iy + f for some integer i, and |f| < |y|.

The rint routine returns the integer (represented as a double precision number) nearest x in the direction of the prevailing rounding mode.

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 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 compiler rounds x towards 0 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 predict. 

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

See Also

abs(3), ieee(3m), math(3m)

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