shithub: riscv

ref: a141f4c53a32d8227f9a490a8e4f7d87445c47d1
dir: /sys/src/libc/port/floor.c/

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