Confusing math problem

Chris Angelico rosuav at gmail.com
Thu Feb 21 21:46:00 CET 2013


On Fri, Feb 22, 2013 at 6:33 AM, Schizoid Man <schiz_man at 21stcentury.com> wrote:
> Hi there,
>
> I run the following code in Python 3.3.0 (on a Windows 7 machine) and Python
> 2.7.3 on a Mac and I get two different results:
>
>        result1.append(math.pow(a,b))
>        result2.append(a**b)

First, are you aware that ** will return int (or sometimes long on
2.7.3), while math.pow() will return a float? That may tell you why
you're seeing differences. That said, though, I wasn't able to
replicate your result using 2.7.3 and 3.3.0 both on Windows - always
9183, indicating 618 of the powers are considered equal. But in
theory, at least, what you're seeing is that 37 of them compare
different in floating point on your Mac build. Something to consider:

print(set(result1)-set(result2))

That should tell you what the extra values are.

ChrisA



More information about the Python-list mailing list