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