Staging
v0.5.1
https://github.com/python/cpython
Revision 06a30b087e8726baa69406a2fd5981331221f1f3 authored by Brett Cannon on 22 October 2004, 06:22:54 UTC, committed by Brett Cannon on 22 October 2004, 06:22:54 UTC
Applies patch #1051866.  Thanks Felix Wiemann.
1 parent 054541e
Raw File
Tip revision: 06a30b087e8726baa69406a2fd5981331221f1f3 authored by Brett Cannon on 22 October 2004, 06:22:54 UTC
Fix minor reST error in Misc/NEWS.
Tip revision: 06a30b0
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