A bug or a documentation error
tim_one at email.msn.com
Fri Sep 15 03:36:31 CEST 2000
It's not a bug, but it's hard to see how to make *look* like it's not
<wink>. What the infix "%" operator does is explained correctly in the
docs. *Accurate* docs for math.fmod would have to say something more like:
Return the value returned by the underlying fmod function in
your platform's implementation of C's math library. See your
platform documentation for an exact definition.
And then the problem is that, in my experience, most platform docs don't
actually *have* an exact definition, and it definitely varies across
platforms. The same is true of many of the math.* functions, which are just
thin wrappers around the platform libm. Rather than just confuse people
more, the math module docs have generally been left cryptic to the point of
Note that you'll get the same kinds of answers running straight C; e.g.,
double x = -3.2;
double y = 1.0;
double quotient = floor(x/y);
double mod = x - quotient * y;
double dmod = fmod(x, y);
printf("%g quotient %.17g %.17g\n", quotient, mod, dmod);
-4 quotient 0.79999999999999982 -0.20000000000000018
for me, today, under Win98SE, using MS's math functions.
Note that the builtin pow isn't the same as math.pow either.
> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Nadav Horesh
> Sent: Thursday, September 14, 2000 5:11 PM
> To: python-list at python.org
> Subject: A bug or a documentation error
> >>> math.fmod.__doc__
> 'fmod(x,y)\012\012Return x % y.'
> >>> math.fmod(-3.2,1)
> >>> (-3.2)%1
> This was taken from Python 2.0b1, but it is very much the same in 1.5.2:
> Is the __doc__ string wrong or is it a bug?
More information about the Python-list