Re: bug in (log)

2022-07-03 Thread Raymond Toy
On Sun, Jul 3, 2022 at 8:10 AM James Cloos  wrote:

> it looks like that bug only harms ratio.  bignum integer seems to be ok.
>
> so aworkarount is, in the caseof a ratio, to take the difference of the
> logs of the numerator and the denominator.
>

This is basically what cmucl does.  But you have to be careful if the
numerator and denominator are very close to each other.  Then you'll take
the difference of two logs that are essentially equal and lose lots or
precision.  IIRC, cmucl doesn't do this if the ratio is close to 1 because
then converting to double-float isn't a problem.  There are other ways to
handle this though, like implementing a log2 function that returns the
integer part and the fraction separately so you don't lose too many
fraction bits when the numbers are huge.

>
> -JimC
> --
> James Cloos  OpenPGP: 0x997A9F17ED7DAEA6
>
>

-- 
Ray


Re: --norc --shell fails

2022-07-03 Thread James Cloos
this works:

#!/usr/bin/env -S ecl --norc --shell

-JimC
-- 
James Cloos  OpenPGP: 0x997A9F17ED7DAEA6



Re: bug in (log)

2022-07-03 Thread James Cloos
it looks like that bug only harms ratio.  bignum integer seems to be ok.

so aworkarount is, in the caseof a ratio, to take the difference of the
logs of the numerator and the denominator.

-JimC
-- 
James Cloos  OpenPGP: 0x997A9F17ED7DAEA6



Re: bug in (log)

2022-07-03 Thread Stas Boukarev
This is permitted by
http://www.lispworks.com/documentation/HyperSpec/Body/12_acc.htm

On Sun, Jul 3, 2022 at 12:10 AM James Cloos  wrote:
>
> (gitlab is uusable; i have to report here.)
>
> ecl 21.2.1 gives:
>
> > (log 1/6319748715279270675921934218987893281199411530039296)
>
> Debugger received error of type: DIVISION-BY-ZERO
> #
> Error flushed.
>
> whereas other cl's (i testyed sbcl and ccl) give results like:
>
> ? (log 1/6319748715279270675921934218987893281199411530039296)
> -119.27552
>
> I tested on amd64 (gentoo) and arm64 (debian and netbsd) with identical
> results.  i did not have a musl box or other bsd to test on.
>
> run with --no-trap-fpe, the result is #.
>
> another example is:
>
> (truncate (log 1/6319748715279270675921934218987893281199418867))
>
> Debugger received error of type: ARITHMETIC-ERROR
> #
>
> whereas this works:
>
> (truncate (log 1/631974871527927067592193421898789328119941867))
>
> -103
> -0.27893066
>
> which of course suggests that the issue is c's long double's precision.
>
> it looks like ecl could use an mpq log function;
> https://github.com/linas/anant might work.
>
> -JimC
> --
> James Cloos  OpenPGP: 0x997A9F17ED7DAEA6
>