[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 0.3*3 == 0.9?
From: |
Jaroslav Hajek |
Subject: |
Re: 0.3*3 == 0.9? |
Date: |
Thu, 26 Aug 2010 07:28:46 +0200 |
2010/8/25 Michael Creel <address@hidden>:
>
>
> 2010/8/25 Jaroslav Hajek <address@hidden>
>>
>> 2010/8/25 Michael Creel <address@hidden>:
>> > 2010/8/25 Jordi Gutiérrez Hermoso <address@hidden>
>> >>
>> >> 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.
>> >
>> > Right, I'm aware of that. My question is whether or not Octave's
>> > comparison
>> > of floats takes it into account. My impression was that it does, so I
>> > was
>> > surprised by this.
>>
>> Interesting. Where did you get that impression from and what did you
>> actually expect Octave to do?
>>
>>
>> --
>> RNDr. Jaroslav Hajek, PhD
>> computing expert & GNU Octave developer
>> Aeronautical Research and Test Institute (VZLU)
>> Prague, Czech Republic
>> url: www.highegg.matfyz.cz
>
> I thought that comparison of floats returned true if the difference was less
> than machine precision. I don't recall if there ever was any basis for that
> belief, though. I guess that I don't really understand what is the
> usefulness of allowing == to operate on floats. Does Matlab work the same
> way?
Certainly :) If == didn't work on floats, you couldn't even do 1 == 1
in Octave. Some numbers are exactly representable, just not all of
them.
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
- 0.3*3 == 0.9?, Michael Creel, 2010/08/25
- Re: 0.3*3 == 0.9?, Jordi Gutiérrez Hermoso, 2010/08/25
- Re: 0.3*3 == 0.9?, Jordi Gutiérrez Hermoso, 2010/08/25
- Re: 0.3*3 == 0.9?, Michael Creel, 2010/08/25
- Re: 0.3*3 == 0.9?, Jordi Gutiérrez Hermoso, 2010/08/25
- Re: 0.3*3 == 0.9?, Jaroslav Hajek, 2010/08/25
- Re: 0.3*3 == 0.9?, Michael Creel, 2010/08/25
- Re: 0.3*3 == 0.9?, José Luis García Pallero, 2010/08/25
- Re: 0.3*3 == 0.9?, Jordi Gutiérrez Hermoso, 2010/08/25
- Re: 0.3*3 == 0.9?,
Jaroslav Hajek <=
Re: 0.3*3 == 0.9?, Marc Weber, 2010/08/25
Re: 0.3*3 == 0.9?, CdeMills, 2010/08/26