File:  [Research Unix] / researchv9 / libc / math / fmod.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:22:00 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv9-SUN3_old, researchv9-SUN3, HEAD
researchv9-SUN3(old)

/* floating-point mod function without infinity or NaN checking */
#include <math.h>
#include <errno.h>

extern int errno;

double
fmod (x, y)
	double x, y;
{
	int sign = 0, yexp;
	double r, yfr, ldexp(), frexp();

	if (y == 0)
		return x;

	if (y < 0)
		y = -y;

	yfr = frexp (y, &yexp);

	if (x < 0) {
		sign = 1;
		r = -x;
	} else
		r = x;

	while (r >= y) {
		int rexp;
		double rfr = frexp (r, &rexp);
		r -= ldexp (y, rexp - yexp - (rfr < yfr));
	}

	if (sign)
		r = -r;
	return r;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.