Re: Bug in srfi-48?
Shiro Kawai <[email protected]> Thu, 12 Oct 2017 10:40:02 -1000
| Newsgroups | gmane.lisp.scheme.srfi.srfi-48 |
|---|---|
| Message-ID | <CALN0JNGfq1S6inv6BNfbQjgN=ZjYNb=Z0PHsNYr1WkjHhXZJmA@mail.gmail.com> |
--001a1134f4606ec4f5055b5f8b56
Content-Type: text/plain; charset="UTF-8"
X-SL-Modified: truncated_text
The bug reproduces in Gauche as well. I think the fix is along this line:
============
*** format.orig.scm Thu Oct 12 10:37:42 2017
--- format.scm Thu Oct 12 10:38:23 2017
***************
*** 80,86 ****
(string-append "0." frac-str)))
0)))
(new-frac
! (substring temp-str 0 digits))
)
(string-append
(if carry? (number->string (+ 1 (string->number
pre-str))) pre-str)
--- 80,88 ----
(string-append "0." frac-str)))
0)))
(new-frac
! (if (> dot-pos digits)
! (substring temp-str (- dot-pos digits) dot-pos)
! (substring temp-str 0 digits)))
)
(string-append
(if carry? (number->string (+ 1 (string->number
pre-str))) pre-str)
============
On Thu, Oct 12, 2017 at 9:42 AM, Donald Allen <[email protected]>
wrote:
>
>
> On 12 October 2017 at 15:07, Arthur A. Gleckler <[email protected]>
> wrote:
>
>> On Thu, Oct 12, 2017 at 6:04 AM, Donald Allen <[email protected]>
>> wrote:
>>
>>
>>> Thanks for the quick response. From your description of the patch, it
>>> sounds like you addressed the error that occurs using Gambit. But did
>>> you also have a look at the odd rounding behavior I reported in my
>>> first message?
>>>
>>
>> earlier:
>>
>> 3> (/ (round (* 1.997554209949891 100)) 100)
>>> 2.
>>
>>
>> I get the same result with MIT Scheme. I must be missing something. Why
>> do you consider it wrong? According to R7RS (and probably earlier versions
>> of the standard),"round returns the closest integer to x, rounding to even
>> when x is halfway between two integers."
>>
>
> Sorry, I wasn't clear. I was talking about this:
>
> 2> (format "~a & ~7,2F\\%\\\\\n" "Framingham Mass Muni Purpose Loan"
> 1.997554209949891)
> "Framingham Mass Muni Purpose Loan & 2.10\\%\\\\\n"
>
> Why does a ~7,2 formatting of something just under 2 result in 2.1? When,
> as you say,
>
> 3> (/ (round (* 1.997554209949891 100)) 100)
> 2.
>
>
>
--001a1134f4606ec4f5055b5f8b56
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-SL-Modified: truncated_html
<div dir=3D"ltr">The bug reproduces in Gauche as well.=C2=A0 I think the fi=
x is along this line:<div><br></div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D</div><div><div>*** format.orig.scm<span style=3D"white-space:pre"> </sp=
an>Thu Oct 12 10:37:42 2017</div><div>--- format.scm<span style=3D"white-sp=
ace:pre"> </span>Thu Oct 12 10:38:23 2017</div><div>***************</div><d=
iv>*** 80,86 ****</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (string-append "0." frac-str)))</div>=
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 0)))</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0(new-frac</div><div>!=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(substring temp-str 0 digits))</d=
iv><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0(string-append</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if carry? (number->string=
(+ 1 (string->number pre-str))) pre-str)</div><div>--- 80,88 ----</div>=
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 (string-append "0." frac-str)))</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 0)))</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(new-frac</div><=
div>!=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0(if (> dot-pos digits)</div><div>!=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0(substring temp-str (- dot-pos digits) dot-pos)</div><div>!=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0(substring temp-str 0 digits)))</div><div>=C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0)</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(strin=
g-append</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 (if carry? (number->string (+ 1 (string->number pre-str=
))) pre-str)</div></div><div><br></div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D</div></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote"=
>On Thu, Oct 12, 2017 at 9:42 AM, Donald Allen <span dir=3D"ltr"><<a hre=
f=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
m</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margi=
n:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
<br><div class=3D"gmail_extra"><br><div class=3D"gmail_quote"><div><div cla=
ss=3D"h5">On 12 October 2017 at 15:07, Arthur A. Gleckler <span dir=3D"ltr"=
><<a href=3D"mailto:[email protected]" target=3D"_blank">srfi@speechco=
de.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"=
margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef=
t:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quot=
e"><span class=3D"m_6859406600005947133gmail-">On Thu, Oct 12, 2017 at 6:04=
AM, Donald Allen <span dir=3D"ltr"><<a href=3D"mailto:donaldcallen@gmai=
l.com" target=3D"_blank">[email protected]</a>></span> wrote:<br><d=
iv>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks for the quick response. From your description of the patch, it<br>
sounds like you addressed the error that occurs using Gambit. But did<br>
you also have a look at the odd rounding behavior I reported in my<br>
first message?<br></blockquote><div><br></div></span><div>earlier:</div><sp=
an class=3D"m_6859406600005947133gmail-"><div><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex"><span style=3D"font-size:12.8px">3> (/ =
(round (* 1.997554209949891 100)) 100)<br></span><span style=3D"font-size:1=
2.8px">2.</span></blockquote><div><br></div></span><div>I get the same resu=
lt with MIT Scheme.=C2=A0 I must be missing something.=C2=A0 Why do you con=
sider it wrong?=C2=A0 According to R7RS (and probably earlier versions of t=
he standard),"round returns the closest integer to x, rounding to even=
when x is halfway between two integers."<span style=3D"font-size:10pt=
;font-family:CMR10">=C2=A0</span></div></div></div></div></blockquote><div>=
<br></div></div></div><div>Sorry, I wasn't clear. I was talking about t=
his:</div><span class=3D""><div><br></div><span style=3D"font-size:12.8px">=
2> (format "~a & ~7,2F\\%\\\\\n" "Framingham Mass Mun=
i Purpose Loan" 1.997554209949891)</span><br style=3D"font-size:12.8px=
"><div><span style=3D"font-size:12.8px">"Framingham Mass Muni Purpose =
Loan &=C2=A0=C2=A0=C2=A0 2.10\\%\\\\\n"</span></div><div><br></div=
></span><div>Why does a ~7,2 formatting of something just under 2 result in=
2.1? When, as you say,</div><span class=3D""><div><br></div><div><span sty=
le=3D"font-size:12.8px">3> (/ (round (* 1.997554209949891 100)) 100)<br>=
</span><span style=3D"font-size:12.8px">2.</span><br></div><div>=C2=A0</div=
></span></div><br></div></div>
</blockquote></div><br></div>
--001a1134f4606ec4f5055b5f8b56--