Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Would the real machine epsilon please stand up?

Subject: Would the real machine epsilon please stand up?

From: Petr Krysl

Date: 24 Jul, 2009 04:06:18

Message: 1 of 4

Here's something to think about for all the curious people out there:

>> 1==1+0.5000000000000001*eps(1)

ans =

     0

>> 1==1+0.50000000000000001*eps(1)

ans =

     1

We are told in the Matlab documentation that "eps returns the distance from 1.0
to the next largest double-precision number, that is eps = 2^(-52)." Compare that with the above computations carried out in Matlab 7.5.

Any ideas?

Subject: Would the real machine epsilon please stand up?

From: James Tursa

Date: 24 Jul, 2009 06:11:01

Message: 2 of 4

"Petr Krysl" <pkryslNOSP@Mucsd.edu> wrote in message <h4bbvq$p3a$1@fred.mathworks.com>...
> Here's something to think about for all the curious people out there:
>
> >> 1==1+0.5000000000000001*eps(1)
>
> ans =
>
> 0
>
> >> 1==1+0.50000000000000001*eps(1)
>
> ans =
>
> 1
>
> We are told in the Matlab documentation that "eps returns the distance from 1.0
> to the next largest double-precision number, that is eps = 2^(-52)." Compare that with the above computations carried out in Matlab 7.5.
>
> Any ideas?

Double precision does not have enough precision to hold the 2nd constant small bit, so calculations round differently. e.g.,

>> format hex
>> 0.5000000000000001
ans =
   3fe0000000000001
>> 0.5000000000000001*eps(1)
ans =
   3ca0000000000001
>> 1+0.5000000000000001*eps(1)
ans =
   3ff0000000000001
>> 0.50000000000000001
ans =
   3fe0000000000000
>> 0.50000000000000001*eps(1)
ans =
   3ca0000000000000
>> 1+0.50000000000000001*eps(1)
ans =
   3ff0000000000000
>> 1
ans =
   3ff0000000000000

There are a gazillion such examples one can construct with floating point arithmetic. No big deal.

James Tursa

Subject: Would the real machine epsilon please stand up?

From: Bruno Luong

Date: 24 Jul, 2009 06:21:02

Message: 3 of 4

"Petr Krysl" <pkryslNOSP@Mucsd.edu> wrote in message <h4bbvq$p3a$1@fred.mathworks.com>...
> Here's something to think about for all the curious people out there:
>
> >> 1==1+0.5000000000000001*eps(1)
>
> ans =
>
> 0
>
> >> 1==1+0.50000000000000001*eps(1)
>
> ans =
>
> 1
>
> We are told in the Matlab documentation that "eps returns the distance from 1.0
> to the next largest double-precision number, that is eps = 2^(-52)." Compare that with the above computations carried out in Matlab 7.5.
>
> Any ideas?

I honestly don't see anything contradictory or strange fact in your examples.

The rhs of the first test is equal to 1: expected, OK.

The rhs of the second test IS equal to 1+eps(1). This is consistent with Matlab doc. Now I can hear you ask "why it is equal", I would reply: "floating point arithmetic".

Bruno

Subject: Would the real machine epsilon please stand up?

From: Petr Krysl

Date: 24 Jul, 2009 14:52:03

Message: 4 of 4

Just a little teaser, James and Bruno. I didn't quite expect the big gray wolves to pounce on it ;)

Petr

Tags for this Thread

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.

Contact us