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: Why is this expression == False?
Type: Stage:
Components: None Versions: Python 2.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: alexanro, doerwalter, mwh, tim.peters
Priority: normal Keywords:

Created on 2004-10-25 10:09 by alexanro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg22846 - (view) Author: Alexander Rødseth (alexanro) Date: 2004-10-25 10:09
I am not sure if this is a bug or not, but I'm very curious 
of the reason for the following result: 
 
>>> from math import * 
>>> theta = pi 
>>> 
e**(complex(0,1)*theta)==cos(theta)+complex(0,1)*sin(theta) 
False 
 
 
This is supposed to be True, unless I've made some typo 
or made some other mistake. It's a version of Euler's 
equation. 
msg22847 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2004-10-25 10:35
Logged In: YES 
user_id=89016

This is due to rounding errors:
>>> from math import *
*>>> e**(1j*pi)
(-1+1.2246063538223773e-16j)
*>>> cos(pi)+1j*sin(pi)
(-1+1.2246063538223773e-16j)

Closing the bug report
msg22848 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2004-10-25 11:09
Logged In: YES 
user_id=6656

Heh.  Walter, the two numbers you show are in fact equal.  Also, 
the expression is True for me.  I wonder what platform Alexander 
is on -- but not very much, attempting to verify equalities 
involving transcedental quantities using finite precision arithmetic 
is always going to be risky.
msg22849 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-10-27 03:35
Logged In: YES 
user_id=31435

Try this one:

>>> 37.0 / 3 / 3 * 9 == 37.0
False

Worry about transcendentals after making peace with basic 
float arithmetic <wink>.
History
Date User Action Args
2022-04-11 14:56:07adminsetgithub: 41073
2004-10-25 10:09:23alexanrocreate