Why 0.1 + 0.2 == 0.3 is false?
stackoverflow.com
Why 0.1 + 0.2 == 0.3 is false?
1–10 of 10 posts
Re: Why 0.1 + 0.2 == 0.3 is false?
#2 % guile
guile> (= (+ 0.1 0.2) 0.3)
#f
[1] - https://www.gnu.org/software/guile/Re: Why 0.1 + 0.2 == 0.3 is false?
#3In guile[1]: % guile guile> (= (+ 0.1 0.2) 0.3) #f [1] - https://www.gnu.org/software/guile/
scheme@(guile-user)> (= (+ 1/10 2/10) 3/10)
$1 = #tRe: Why 0.1 + 0.2 == 0.3 is false?
#4In guile[1]: % guile guile> (= (+ 0.1 0.2) 0.3) #f [1] - https://www.gnu.org/software/guile/
Guile(and most Lisps such as Common Lisp) support rationals specifically to avoid this problem, why not just use them ? scheme@(guile-user)> (= (+ 1/10 2/10) 3/10) $1 = #t
$ perl6
> 0.1 + 0.2 == 0.3
True
> (0.1 + 0.2).perl
3/10
For perl5 you must use the bigrat pragma: $ re.pl
> 0.1 + 0.2 != 0.3
1
> use bigrat;
> 0.1 + 0.2 == 0.3
1
ref: http://perldoc.perl.org/bigrat.htmlRe: Why 0.1 + 0.2 == 0.3 is false?
#5(Spoiler alert: the answer is that the addition is done at compile time rather than run time.)
Re: Why 0.1 + 0.2 == 0.3 is false?
#6Re: Why 0.1 + 0.2 == 0.3 is false?
#7In guile[1]: % guile guile> (= (+ 0.1 0.2) 0.3) #f [1] - https://www.gnu.org/software/guile/
Guile(and most Lisps such as Common Lisp) support rationals specifically to avoid this problem, why not just use them ? scheme@(guile-user)> (= (+ 1/10 2/10) 3/10) $1 = #t
Sometimes decimal notation is the most natural, and sometimes you're copying numbers in decimal notation out of a book, wikipedia, or some other publication.
Re: Why 0.1 + 0.2 == 0.3 is false?
#8On a side note, Excel is infuriatingly inconsistent: some operations work in a way that .1 + .2 == .3 (for example, try `=0.1+0.2=0.3`) but others fall apart (displayed as a fraction with one digit, 0.3 -> 2/7 but 0.1+0.2 -> 1/3)
Re: Why 0.1 + 0.2 == 0.3 is false?
#9On a side note, Excel is infuriatingly inconsistent: some operations work in a way that .1 + .2 == .3 (for example, try `=0.1+0.2=0.3`) but others fall apart (displayed as a fraction with one digit, 0.3 -> 2/7 but 0.1+0.2 -> 1/3)
floating point is hard. backwards compatibility is even harder
Re: Why 0.1 + 0.2 == 0.3 is false?
#10Here is one such instance. http://www.yuiblog.com/blog/2009/03/10/when-you-cant-count-o...
He has been on a crusade to introduce a decimal based floating point standard because he believes it is finally time we revisit this decision to use binary floating point.
Edit: spelling