Elektrine lite

← Feed

@simon_brooke@mastodon.scot

Post #1782127

2026-04-27 06:58 UTC

@screwlisp AH! OK, now that would be interesting! OK, so the way I'm doing arithmetic at present is if the args are rational and integer, I convert to rational, so the result will be rational, but if any of the args is float the result will be float. I notice that SBCL does not do this: CL-USER[1]: (expt 1/2 3/4) 0.59460354 But, my naive implementation of `expt` does not handle rationals... There's a good discussion of the issue here: https://www.lispworks.com/documentation/HyperSpec/Issues/iss153_w.htm #Lisp

Replies (2)

  • @simon_brooke@mastodon.scot 2026-04-27 07:10

    @screwlisp **but**, if you convert an integer to ratio, then the divisor will necessarily be one; so if it is true that "... an implementation [of expt] might choose to compute (expt x 3/2) as if it had been written (sqrt (expt x 3))" (and at this time in the morning I am not awake enough to evaluate this in my head), then yes, the value of `(expt 3/4 3)` should be a complex number. But if that's so, why is (expt 0.75 3) not also a complex number?

    Open ##1782128

  • @vnikolov@ieji.de 2026-04-27 17:07

    @simon_brooke wrote: «... SBCL does not do this: CL-USER[1]: (expt 1/2 3/4) 0.59460354 » What is it that SBCL does not do here? Note that 1/2 to the power of 3/4 is an (algebraic) irrational number, so the value can only be a floating-point number in a Common Lisp implementation without rather fancy extensions. @screwlisp

    Open ##1782131