1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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); }