[ python-Bugs-1053629 ] Why is this expression == False?

SourceForge.net noreply at sourceforge.net
Wed Oct 27 05:35:42 CEST 2004


Bugs item #1053629, was opened at 2004-10-25 06:09
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1053629&group_id=5470

Category: None
Group: Python 2.3
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Alexander Rødseth (alexanro)
Assigned to: Nobody/Anonymous (nobody)
Summary: Why is this expression == False?

Initial Comment:
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. 

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2004-10-26 23:35

Message:
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>.

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2004-10-25 07:09

Message:
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.

----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2004-10-25 06:35

Message:
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

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1053629&group_id=5470


More information about the Python-bugs-list mailing list