Commit | Line | Data |
---|---|---|
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 |
10 | fabs, floor, ceil, rint \- absolute value, floor, ceiling, and |
11 | round-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 | 29 | Fabs returns the absolute value |\|x\||. |
56017266 | 30 | .PP |
f9628029 | 31 | Floor returns the largest integer no greater than x. |
56017266 | 32 | .PP |
f9628029 KM |
33 | Ceil returns the smallest integer no less than x. |
34 | .PP | |
35 | Rint returns the integer (represented as a double precision number) | |
36 | nearest x in the direction of the prevailing rounding mode. | |
f9628029 KM |
37 | .SH NOTES |
38 | On a VAX, rint(x) is equivalent to adding half to the magnitude | |
39 | and then rounding towards zero. | |
40 | .PP | |
41 | In the default rounding mode, to nearest, | |
42 | on a machine that conforms to IEEE 754, | |
43 | rint(x) is the integer nearest x with the additional stipulation | |
44 | that if |rint(x)\-x|=1/2 then rint(x) is even. | |
45 | Other rounding modes can make rint act like floor, or like ceil, | |
46 | or round towards zero. | |
47 | .PP | |
48 | Another way to obtain an integer near x is to declare (in C) | |
49 | .RS | |
50 | double x;\0\0\0\0 int k;\0\0\0\0k\0=\0x; | |
51 | .RE | |
52 | Most C compilers round x towards 0 to get the integer k, but | |
53 | some do otherwise. | |
54 | If in doubt, use floor, ceil, or rint first, whichever you intend. | |
55 | Also note that, if x is larger than k can accommodate, the value of | |
56 | k and the presence or absence of an integer overflow are hard to | |
57 | predict. | |
8220ec5a MK |
58 | .SH SEE ALSO |
59 | abs(3), | |
60 | ieee(3M), | |
61 | math(3M) |