add Berkeley specific header
[unix-history] / usr / src / lib / libm / common_source / floor.3
CommitLineData
f9628029
KM
1.\" Copyright (c) 1985 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
8220ec5a 5.\" @(#)floor.3 6.4 (Berkeley) %G%
f9628029
KM
6.\"
7.TH FLOOR 3M ""
8.UC 4
56017266 9.SH NAME
f9628029
KM
10fabs, floor, ceil, rint \- absolute value, floor, ceiling, and
11round-to-nearest functions
56017266
KM
12.SH SYNOPSIS
13.nf
14.B #include <math.h>
15.PP
16.B double floor(x)
17.B double x;
18.PP
19.B double ceil(x)
20.B double x;
21.PP
22.B double fabs(x)
23.B double x;
f9628029
KM
24.PP
25.B double rint(x)
26.B double x;
27.fi
56017266 28.SH DESCRIPTION
f9628029 29Fabs returns the absolute value |\|x\||.
56017266 30.PP
f9628029 31Floor returns the largest integer no greater than x.
56017266 32.PP
f9628029
KM
33Ceil returns the smallest integer no less than x.
34.PP
35Rint returns the integer (represented as a double precision number)
36nearest x in the direction of the prevailing rounding mode.
f9628029
KM
37.SH NOTES
38On a VAX, rint(x) is equivalent to adding half to the magnitude
39and then rounding towards zero.
40.PP
41In the default rounding mode, to nearest,
42on a machine that conforms to IEEE 754,
43rint(x) is the integer nearest x with the additional stipulation
44that if |rint(x)\-x|=1/2 then rint(x) is even.
45Other rounding modes can make rint act like floor, or like ceil,
46or round towards zero.
47.PP
48Another way to obtain an integer near x is to declare (in C)
49.RS
50double x;\0\0\0\0 int k;\0\0\0\0k\0=\0x;
51.RE
52Most C compilers round x towards 0 to get the integer k, but
53some do otherwise.
54If in doubt, use floor, ceil, or rint first, whichever you intend.
55Also note that, if x is larger than k can accommodate, the value of
56k and the presence or absence of an integer overflow are hard to
57predict.
8220ec5a
MK
58.SH SEE ALSO
59abs(3),
60ieee(3M),
61math(3M)