help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 0.3*3 == 0.9?


From: Jordi Gutiérrez Hermoso
Subject: Re: 0.3*3 == 0.9?
Date: Wed, 25 Aug 2010 09:23:28 -0500

2010/8/25 Jordi Gutiérrez Hermoso <address@hidden>:
> On 25 August 2010 09:13, Michael Creel <address@hidden> wrote:
>> octave:1> 0.3*2 == 0.6
>> ans =  1
>> octave:2> 0.3*3 == 0.9
>> ans = 0
>> octave:3>
>
> http://docs.sun.com/source/806-3568/ncg_goldberg.html

Oops, sorry, I hit the "send" button too soon.

Anyways, yes, this is completely normal. 0.3 has an infinite binary
expansion because its denominator has factors other than 2, so you'll
get a rounding error. Use something like abs(0.3*3 - 0.9) < 10*eps
instead or whatever seems like an appropriate approximation.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]