.\" Copyright (c) 1985 Regents of the University of California. .\" All rights reserved. The Berkeley software License Agreement .\" specifies the terms and conditions for redistribution. .\" .\" @(#)floor.3m 6.4 (Berkeley) 5/12/86 .\" .TH FLOOR 3 "May 12, 1986" .UC 4 .SH NAME floor, ceil, fabs, rint \- floor, ceiling, absolute value, and round-to-nearest functions .SH SYNOPSIS .nf .ft B #include double floor(double \fIx\fP) double ceil(double \fIx\fP) double fabs(double \fIx\fP) double rint(double \fIx\fP) .ft R .fi .SH DESCRIPTION Floor returns the largest integer no greater than x. .PP Ceil returns the smallest integer no less than x. .PP Fabs returns the absolute value |\|x\||. .PP Rint returns the integer (represented as a double precision number) nearest x in the direction of the prevailing rounding mode. .SH NOTES In the default rounding mode, to nearest, .ig \" Minix is! on a machine that conforms to IEEE 754, .. 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. .PP Another way to obtain an integer near x is to declare (in C) .PP .RS double x;\0\0\0\0 int k;\0\0\0\0k\0=\0x; .RE .PP Most C compilers round x towards 0 to get the integer k, but some do otherwise. If in doubt, use floor, ceil, or rint first, whichever you intend. 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. .SH SEE ALSO .BR abs (3), .BR ieee (3), .BR math (3).