Staging
v0.5.1
https://github.com/python/cpython
Revision 91cfc50a43f1bb4354ccb1f22b9fad5eb5a61426 authored by Andrew M. Kuchling on 20 May 2003, 18:13:14 UTC, committed by Andrew M. Kuchling on 20 May 2003, 18:13:14 UTC
1 parent a92eb4b
Raw File
Tip revision: 91cfc50a43f1bb4354ccb1f22b9fad5eb5a61426 authored by Andrew M. Kuchling on 20 May 2003, 18:13:14 UTC
Backport: Don't mention __slots__ as a technique for error avoidance
Tip revision: 91cfc50
fmod.c

/* Portable fmod(x, y) implementation for systems that don't have it */

#include "pyconfig.h"

#include "pyport.h"
#include <errno.h>

double
fmod(double x, double y)
{
	double i, f;
	
	if (y == 0.0) {
		errno = EDOM;
		return 0.0;
	}
	
	/* return f such that x = i*y + f for some integer i
	   such that |f| < |y| and f has the same sign as x */
	
	i = floor(x/y);
	f = x - i*y;
	if ((x < 0.0) != (y < 0.0))
		f = f-y;
	return f;
}
back to top