diff options
Diffstat (limited to 'libkern/floor.c')
| -rw-r--r-- | libkern/floor.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libkern/floor.c b/libkern/floor.c new file mode 100644 index 00000000..86e6c816 --- /dev/null +++ b/libkern/floor.c @@ -0,0 +1,26 @@ +#include <lib9.h> +/* + * floor and ceil-- greatest integer <= arg + * (resp least >=) + */ + +double +floor(double d) +{ + double fract; + + if(d < 0) { + fract = modf(-d, &d); + if(fract != 0.0) + d += 1; + d = -d; + } else + modf(d, &d); + return d; +} + +double +ceil(double d) +{ + return -floor(-d); +} |
