Re: bug in (log)

Raymond Toy <[email protected]> Sun, 3 Jul 2022 09:05:32 -0700
Newsgroups gmane.lisp.ecl.general
Message-ID <CAG14z1G3DXh4+YwEcfQNNNrJi3fQa5k1P3=gw=4o=2TJfUubYQ@mail.gmail.com>
--000000000000a094b705e2e8caf1
Content-Type: text/plain; charset="UTF-8"

On Sun, Jul 3, 2022 at 8:10 AM James Cloos <cloos-GRsvFm/Gh/[email protected]> 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 <cloos-GRsvFm/Gh/[email protected]>         OpenPGP: 0x997A9F17ED7DAEA6
>
>

-- 
Ray

--000000000000a094b705e2e8caf1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-family:arial,helvetica,sans-serif;font-size:small"><br></div></div><br><d=
iv class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jul =
3, 2022 at 8:10 AM James Cloos &lt;<a href=3D"mailto:cloos-GRsvFm/Gh/[email protected]">clo=
os-GRsvFm/Gh/[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padd=
ing-left:1ex">it looks like that bug only harms ratio.=C2=A0 bignum integer=
 seems to be ok.<br>
<br>
so aworkarount is, in the caseof a ratio, to take the difference of the<br>
logs of the numerator and the denominator.<br></blockquote><div><br></div><=
div style=3D"font-family:arial,helvetica,sans-serif;font-size:small" class=
=3D"gmail_default">This is basically what cmucl does.=C2=A0 But you have to=
 be careful if the numerator and denominator are very close to each other.=
=C2=A0 Then you&#39;ll take the difference of two logs that are essentially=
 equal and lose lots or precision.=C2=A0 IIRC, cmucl doesn&#39;t do this if=
 the ratio is close to 1 because then converting to double-float isn&#39;t =
a problem.=C2=A0 There are other ways to handle this though, like implement=
ing a log2 function that returns the integer part and the fraction separate=
ly so you don&#39;t lose too many fraction bits when the numbers are huge.<=
br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
-JimC<br>
-- <br>
James Cloos &lt;<a href=3D"mailto:cloos-GRsvFm/Gh/[email protected]" target=3D"_blank">cloo=
[email protected]</a>&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0OpenPGP: 0x997A9F17E=
D7DAEA6<br>
<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature"><div dir=3D"ltr"><div></div>Ray<br></div></div></div>

--000000000000a094b705e2e8caf1--