Re: Bug in srfi-48?
Marc Feeley <[email protected]> Fri, 13 Oct 2017 13:51:21 -0400
| Newsgroups | gmane.lisp.scheme.srfi.srfi-48 |
|---|---|
| Message-ID | <[email protected]> |
I=E2=80=99ve found this code works well for me=E2=80=A6
(define (num->string num w d) ; w =3D total width, d =3D decimals
(let ((n (round (* (abs (inexact->exact num)) (expt 10 d)))))
(let ((i (quotient n (expt 10 d)))
(f (modulo n (expt 10 d))))
(let ((si (string-append
(if (< num 0) "-" "")
(number->string i 10)))
(sf (if (> d 0)
(let ((sf (number->string (+ f (expt 10 d)) 10)))
(string-set! sf 0 #\.)
sf)
"")))
(let ((lsi (string-length si))
(lsf (string-length sf)))
(let ((blanks (- w (+ lsi lsf))))
(string-append (make-string (max blanks 0) #\space) si sf)))))))
Perhaps that=E2=80=99s better for your purpose than srfi-48.
Marc
> On Oct 13, 2017, at 12:13 PM, Donald Allen <[email protected]> wrote:
>=20
> Here's another:
>=20
>> (load "srfi-48.scm")
> "/home/dca/Software/newcash/gLibraries/srfi-48/srfi-48.scm"
>> (format "~8,0F" -14.99995999999362)
> " -13."
>> (round -14.99995999999362)
> -15.
>>=20
>=20
> The version of srfi-48.scm I am using has both of yesterday's patches
> installed. I saw the symptoms of the above before installing these
> patches, so I don't think they are the cause of this error.
>=20
> On 13 October 2017 at 11:58, Donald Allen <[email protected]> wrote:
>> The patches offered thus far seem to have addressed the problems I
>> previously reported. But here's another:
>>=20
>> 1> (format "~7,2F" 18.0000000000008)
>> " 18.0."
>> 1>
>>=20
>> And I am seeing symptoms in my application that other numbers are not
>> being displayed correctly. I have not chased them down yet, but will
>> try to do so and report if I find anything.
>>=20
>> I must say that it's disconcerting to be finding all these problems in
>> code that was finalized in 2004. I think at the very least, a warning
>> should be posted in an appropriate place that issues have been found
>> with this srfi, efforts are being made to correct them, and until
>> further notice, its use may not produce correct results.
>>=20
>> /Don
>>=20
>> On 12 October 2017 at 22:09, Donald Allen <[email protected]> wrote:
>>> On 12 October 2017 at 19:13, Arthur A. Gleckler <[email protected]> w=
rote:
>>>> On Thu, Oct 12, 2017 at 12:42 PM, Donald Allen <[email protected]>
>>>> wrote:
>>>>=20
>>>>>=20
>>>>> Sorry, I wasn't clear. I was talking about this:
>>>>=20
>>>>=20
>>>> I apologize. That should have been obvious to me. I've been trying t=
o do
>>>> too many things at once over the past few days.
>>>>=20
>>>> Would you mind trying Shiro Kawai's patch?
>>>=20
>>> I applied both yours and Shiro Kawai"s patches:
>>>=20
>>> 1> (format "~a & ~7,2F\\%\\\\\n" "Framingham Mass Muni Purpose Loan"
>>> 1.997554209949891)
>>> "Framingham Mass Muni Purpose Loan & 2.00\\%\\\\\n"
>>> 1> (format "~a & ~7,2F\\%\\\\\n" "Framingham Mass Muni Purpose Loan"
>>> .997554209949891)
>>> "Framingham Mass Muni Purpose Loan & 1.00\\%\\\\\n"
>>> 1> (format "~7,2F" .997554209949891)
>>> " 1.00"
>>> 1> (format "~7,2F" .99755420)
>>> " 1.00"
>>> 1> (format "~7,2F" .99755)
>>> " 1.00"
>>> 1> (format "~7,2F" .997)
>>> " 1.00"
>>> 1> (format "~7,2F" .99)
>>> " .99"
>>> 1>
>>>=20
>>> Looks good. Thanks very much.
>>>=20
>>> /Don
>>>=20
>>>>=20
>>>> (Thank you, Mr. Kawai.)
Marc