Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libm / mathfp / s_floor.c
blobe407ea237c83e8e8d81dd25d7b1810b92ee0cdd0
2 /* @(#)z_floor.c 1.0 98/08/13 */
4 /*
5 FUNCTION
6 <<floor>>, <<floorf>>, <<ceil>>, <<ceilf>>---floor and ceiling
7 INDEX
8 floor
9 INDEX
10 floorf
11 INDEX
12 ceil
13 INDEX
14 ceilf
16 SYNOPSIS
17 #include <math.h>
18 double floor(double <[x]>);
19 float floorf(float <[x]>);
20 double ceil(double <[x]>);
21 float ceilf(float <[x]>);
23 DESCRIPTION
24 <<floor>> and <<floorf>> find
25 @tex
26 $\lfloor x \rfloor$,
27 @end tex
28 the nearest integer less than or equal to <[x]>.
29 <<ceil>> and <<ceilf>> find
30 @tex
31 $\lceil x\rceil$,
32 @end tex
33 the nearest integer greater than or equal to <[x]>.
35 RETURNS
36 <<floor>> and <<ceil>> return the integer result as a double.
37 <<floorf>> and <<ceilf>> return the integer result as a float.
39 PORTABILITY
40 <<floor>> and <<ceil>> are ANSI.
41 <<floorf>> and <<ceilf>> are extensions.
45 /*****************************************************************
46 * floor
48 * Input:
49 * x - floating point value
51 * Output:
52 * Smallest integer less than x.
54 * Description:
55 * This routine returns the smallest integer less than x.
57 *****************************************************************/
59 #include "fdlibm.h"
60 #include "zmath.h"
62 #ifndef _DOUBLE_IS_32BITS
64 double
65 floor (double x)
67 double f, y;
69 if (x > -1.0 && x < 1.0)
70 return (x >= 0 ? 0 : -1.0);
72 y = modf (x, &f);
74 if (y == 0.0)
75 return (x);
77 return (x >= 0 ? f : f - 1.0);
80 #endif /* _DOUBLE_IS_32BITS */