Staging
v0.8.1
https://github.com/python/cpython
Revision 6314b2244c5daf0e8c8cc61db05c8c9498f111a7 authored by Fred Drake on 22 May 2003, 15:09:55 UTC, committed by Fred Drake on 22 May 2003, 15:09:55 UTC
1 parent 49a5f47
Raw File
Tip revision: 6314b2244c5daf0e8c8cc61db05c8c9498f111a7 authored by Fred Drake on 22 May 2003, 15:09:55 UTC
Minor elaboration in the information about reporting errors.
Tip revision: 6314b22
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