This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Wrong math calculation
Type: behavior Stage:
Components: Versions: Python 3.0
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: bubersson, rhettinger
Priority: normal Keywords:

Created on 2008-10-20 20:08 by bubersson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg75002 - (view) Author: Petr (bubersson) Date: 2008-10-20 20:07
Hi, I've just tried some math functions in python3.0, but there's an 
wrong calculation (see the example). sin(pi/4) should be same as 
(2^.5)/2, but the result is different in last two digits. I don't know 
if it's an expected behaviour and this is my first posted issue. 

Python 3.0rc1 (r30rc1:66507, Sep 18 2008, 14:47:08) [MSC v.1500 32 bit 
(Intel)]
>>> from math import *
>>> sin(pi/4)==(2**0.5)/2
False

sin(pi/4)==0.70710678118654746
(2**0.5)/2==0.70710678118654757

bubersson
msg75004 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-10-20 20:35
None of these calculations are going to work out exactly.  Look-up "what
every computer scientist needs to know about floating point" and see the
floating-point appendix in the Python tutorial.  In this case, the
difference is only one bit in the last place:

  >>> 0.70710678118654746.hex()
  '0x1.6a09e667f3bccp-1'
  >>> 0.70710678118654757.hex()
  '0x1.6a09e667f3bcdp-1'
History
Date User Action Args
2022-04-11 14:56:40adminsetgithub: 48405
2008-10-20 20:35:32rhettingersetstatus: open -> closed
resolution: not a bug
messages: + msg75004
nosy: + rhettinger
2008-10-20 20:08:00buberssoncreate