shithub: p9-stm32-example-bare

ref: 385ecf9c11ba7114801e877090951e1785698051
dir: /libkern/floor.c/

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