diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2017-12-15 09:38:53 -0500 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2017-12-15 09:39:34 -0500 |
commit | f95a4a932476be2ba99e2fd081e8d2bc6ea12813 (patch) | |
tree | 75f67192cb2d7b7b575c94edda318e475239b63c /newlib/libm/mathfp/s_floor.c | |
parent | f60aca96985e68c7d8a52eb7bc955fb80e132f73 (diff) |
Import newlib and create makefile
Diffstat (limited to 'newlib/libm/mathfp/s_floor.c')
-rw-r--r-- | newlib/libm/mathfp/s_floor.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/newlib/libm/mathfp/s_floor.c b/newlib/libm/mathfp/s_floor.c new file mode 100644 index 0000000..0dbc207 --- /dev/null +++ b/newlib/libm/mathfp/s_floor.c @@ -0,0 +1,92 @@ + +/* @(#)z_floor.c 1.0 98/08/13 */ + +/* +FUNCTION +<<floor>>, <<floorf>>, <<ceil>>, <<ceilf>>---floor and ceiling +INDEX + floor +INDEX + floorf +INDEX + ceil +INDEX + ceilf + +ANSI_SYNOPSIS + #include <math.h> + double floor(double <[x]>); + float floorf(float <[x]>); + double ceil(double <[x]>); + float ceilf(float <[x]>); + +TRAD_SYNOPSIS + #include <math.h> + double floor(<[x]>) + double <[x]>; + float floorf(<[x]>) + float <[x]>; + double ceil(<[x]>) + double <[x]>; + float ceilf(<[x]>) + float <[x]>; + +DESCRIPTION +<<floor>> and <<floorf>> find +@tex +$\lfloor x \rfloor$, +@end tex +the nearest integer less than or equal to <[x]>. +<<ceil>> and <<ceilf>> find +@tex +$\lceil x\rceil$, +@end tex +the nearest integer greater than or equal to <[x]>. + +RETURNS +<<floor>> and <<ceil>> return the integer result as a double. +<<floorf>> and <<ceilf>> return the integer result as a float. + +PORTABILITY +<<floor>> and <<ceil>> are ANSI. +<<floorf>> and <<ceilf>> are extensions. + +*/ + +/***************************************************************** + * floor + * + * Input: + * x - floating point value + * + * Output: + * Smallest integer less than x. + * + * Description: + * This routine returns the smallest integer less than x. + * + *****************************************************************/ + +#include "fdlibm.h" +#include "zmath.h" + +#ifndef _DOUBLE_IS_32BITS + +double +_DEFUN (floor, (double), + double x) +{ + double f, y; + + if (x > -1.0 && x < 1.0) + return (x >= 0 ? 0 : -1.0); + + y = modf (x, &f); + + if (y == 0.0) + return (x); + + return (x >= 0 ? f : f - 1.0); +} + +#endif /* _DOUBLE_IS_32BITS */ |