Staging
v0.8.1
https://github.com/python/cpython
Revision 6f5d3f326f8c98dc4c53b422a92306e391e83cc2 authored by Jeffrey Yasskin on 10 December 2008, 17:23:20 UTC, committed by Jeffrey Yasskin on 10 December 2008, 17:23:20 UTC
1 parent 6f63190
Raw File
Tip revision: 6f5d3f326f8c98dc4c53b422a92306e391e83cc2 authored by Jeffrey Yasskin on 10 December 2008, 17:23:20 UTC
Backport issue 4597 to python 2.5.3: Fixed several opcodes that weren't always
Tip revision: 6f5d3f3
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