view Python/fmod.c @ 17997:27f2422ea335 legacy-trunk

Change cascaded if stmts to switch stmt in vgetargs1(). In the default branch, keep three ifs that are used if level == 0, the most common case. Note that first if here is a slight optimization for the 'O' format. Second part of SF patch 426072.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Tue, 29 May 2001 17:46:19 +0000
parents 6f6f965c5e2d
children 2dea40e40d9d
line wrap: on
line source


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

#include "config.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;
}