Re:Ask HN: How to rediscover the joy of programming?
by reitzensteinm on Wednesday April 15, 2020 @01:09AM
(#22874729)
This just means that 0.3 has the same internal representation as the result of (0.1 + 0.2).
Internally, they're probably both 0.30000000000000004 (depending on precision), so an equality check returns true.
It could also be that they're both 3/10 rational numbers, but given other tests in this thread that's likely not the case out the box.
Re:Ask HN: How to rediscover the joy of programming?
by yellowapple on Thursday April 16, 2020 @04:11AM
(#22887234)
northrup@Topaz:~$ sbcl
This is SBCL 1.5.8, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (- 0.3 3/10)
0.0
* (= (- 0.3 3/10) 0)
T
* (= (- 3/10 0.3) 0)
T
* (= 0.3 3/10)
NIL
So yeah, 0.3 and 3/10 are definitely distinct, but still apparently net out to exactly 0 nonetheless.
Re:Ask HN: How to rediscover the joy of programming?
by fiddlerwoaroof on Wednesday April 15, 2020 @02:21AM
(#22875121)
CL-USER(3): (rational (+ 0.1 0.2))
5033165/16777216
CL-USER(3): (rational 0.3)
5033165/16777216
"Financial applications" happen to be pretty common reasons for number crunching :)