|
|
Log in / Subscribe / Register

Advanced computing with IPython

Advanced computing with IPython

Posted Jun 20, 2018 18:22 UTC (Wed) by excors (subscriber, #95769)
In reply to: Advanced computing with IPython by yroyon
Parent article: Advanced computing with IPython

They should both be using double-precision floats, and should calculate 1+1/1e8 identically. But the ** operator is much more complicated and can be implemented in many different ways with different levels of accuracy and performance. I guess Python probably uses pow() from the C standard library, so might not even give the same answer if you run it on Windows, and the Fortran compiler presumably has its own implementation. So it's more a consequence of their maths libraries than of the language itself, exacerbated by doing a silly computation .


to post comments

Advanced computing with IPython

Posted Jun 20, 2018 18:39 UTC (Wed) by excors (subscriber, #95769) [Link]

Oh, and also the Python version returns the value from n=1e8-1, while the Fortran version goes up to n=1e8, because 'range' takes an exclusive upper bound and 'do' is inclusive. But even after fixing that, it seems there's still a (slightly smaller) difference in their outputs.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds