Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: pi^2*pi^2==pi^4 gives 0 (untrue)?

Subject: pi^2*pi^2==pi^4 gives 0 (untrue)?

From: Leonidas Bantis

Date: 12 Jan, 2008 06:23:23

Message: 1 of 4

Dear Matlab Community,

Why the following?..

pi^2*pi^2==pi^4 gives 0 (untrue)?

exp(5)*exp(5)==exp(10) gives 0 (untrue)?

(2/3)^5*(2/3)^5==(2/3)^10 gives 0 (untrue)?



Is there any problem with the endless digits?


(2/3)*(2/3)==(2/3)^2 gives 1 though..

Thanks in advance

Subject: pi^2*pi^2==pi^4 gives 0 (untrue)?

From: Roger Stafford

Date: 12 Jan, 2008 07:39:02

Message: 2 of 4

"Leonidas Bantis" <sasm05013@sas.aegean.gr> wrote in message <fm9mcr
$52l$1@fred.mathworks.com>...
> Dear Matlab Community,
>
> Why the following?..
>
> pi^2*pi^2==pi^4 gives 0 (untrue)?
>
> exp(5)*exp(5)==exp(10) gives 0 (untrue)?
>
> (2/3)^5*(2/3)^5==(2/3)^10 gives 0 (untrue)?
>
> Is there any problem with the endless digits?
>
> (2/3)*(2/3)==(2/3)^2 gives 1 though..
>
> Thanks in advance
--------
  You will note that in each case the two quantities that would ideally be
exactly equal, differ in only their least bit out of the 53 bits. That is an error
of only one part in around 10^16. This is about all you can expect of a
computer with this many bits, arriving at a result as it does by two different
computational paths and making roundoff errors along the way.

  I like to give the example of a violation of the basic associative law of
addition:

 3/14 + (3/14 + 15/14) ~= (3/14 + 3/14) + 15/14

According to many computers, digital or binary, these are not equal (though
again they differ only in their least bit.)

Roger Stafford


Subject: pi^2*pi^2==pi^4 gives 0 (untrue)?

From: Martin Jørgensen

Date: 12 Jan, 2008 16:24:08

Message: 3 of 4

Leonidas Bantis wrote:
> Dear Matlab Community,
>
> Why the following?..
>
> pi^2*pi^2==pi^4 gives 0 (untrue)?
>
> exp(5)*exp(5)==exp(10) gives 0 (untrue)?
>
> (2/3)^5*(2/3)^5==(2/3)^10 gives 0 (untrue)?


You need to do/evaluate:

"abs(pi^2*pi^2 - pi^4) < tolerance", approx 1e-14 or whatever

etc.


Regards,
Martin

Subject: pi^2*pi^2==pi^4 gives 0 (untrue)?

From: Scott Seidman

Date: 14 Jan, 2008 16:56:04

Message: 4 of 4

"Leonidas Bantis" <sasm05013@sas.aegean.gr> wrote in news:fm9mcr$52l$1
@fred.mathworks.com:

> Dear Matlab Community,
>
> Why the following?..
>
> pi^2*pi^2==pi^4 gives 0 (untrue)?
>
> exp(5)*exp(5)==exp(10) gives 0 (untrue)?
>
> (2/3)^5*(2/3)^5==(2/3)^10 gives 0 (untrue)?
>
>
>
> Is there any problem with the endless digits?
>
>
> (2/3)*(2/3)==(2/3)^2 gives 1 though..
>
> Thanks in advance


One must be extremely careful when doing equality comparisions on floating
point data. It's generally not a great idea.

--
Scott
Reverse name to reply

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
relational operators Leonidas Bantis 12 Jan, 2008 01:25:04
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics