Elektrine lite

← Feed

@vnikolov@ieji.de

Post #1782145

2026-04-28 03:36 UTC

@simon_brooke wrote: «Interestingly, SBCL doesn't think (√2)² = 2: CL-USER[1]: (sqrt 2) 1.4142135 CL-USER[2]: (* (sqrt 2)(sqrt 2)) 1.9999999» This kind of (correct) behavior is by far not specific to SBCL or even Lisp. Note that the value of (sqrt 2) (or sqrt(2) in other languages) is of course not √2, but an approximation. Maybe one expects that the above product tests exactly equal to 2 in a computer algebra system or better, but those are very different beasts; I don't think I have ever tried it myself, though. «I don't know how many bits SBCL's floating point representation is, but that sort of thing is exactly why I don't want to drop to floats when I don't have to.» Indeed, but I am not aware of a (very) smart representation of irrational algebraic numbers that is useful for doing ordinary calculations with them. If one has been found, that would be a great achievement. SBCL's `single-float' is 32 bits (as with many other implementations), but that is not particularly important in this context. To repeat the well-known, no floating-point format can represent exact values of irrational numbers. @screwlisp

Replies (1)

  • @simon_brooke@mastodon.scot 2026-04-28 06:41

    @vnikolov @screwlisp No, indeed. Obviously the point of irrational numbers is that they can't be exactly represented in numerals (every decimal number is inevitably rational). But there must be some quantity which is the quantity which, when multiplied by itself, yields integer two. It must be possible to so closely approximate that quantity that the result of multiplying the approximation by itself is practically indistinguishable from two. /Continued

    Open ##1782146