shithub: riscv

ref: 855cf4326f5a07d7142c2d8918f5fa856d912b85
dir: /sys/src/ape/lib/ap/math/floor.c/

View raw version
#include <math.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);
}