Page 1 of 1

float representation on FreeBSD 10.1-RELEASE-p10

Posted: Tue Oct 27, 2015 11:29 am
by Kirill
newLISP v.10.6.2 on FreeBSD 10.1 (on NearlyFreeSpeech) represents floats in some trange way:

Code: Select all

uptime:/home/public> newlisp
newLISP v.10.6.2 64-bit on BSD IPv4/6 UTF-8 libffi, options: newlisp -h

> (float 99.0)
99
> (float [b]99.1[/b])
[b]99.09999999999999[/b]
> (float 99.2)
99.2
> (float 99.7)
99.7
> (float 99.8)
99.8
> (float [b]99.9[/b])
[b]99.90000000000001[/b]
>
I'm not sure if it is OS or newLISP, but I've tried the exercise with newlisp 10.6.4 on OpenBSD 5.8 with the same results:

Code: Select all

km@ftp ~ $ newlisp
newLISP v.10.6.4 64-bit on BSD IPv4/6 UTF-8, options: newlisp -h

> (float 99.9)
99.90000000000001
> (float 99.8)
99.8
> (float 99.1)
99.09999999999999
> (float 99.0)
99
I'm fully sure it wasn't like this before. I discovered the error after NearlyFreeSpeech moved my site to a new realm (it's how they call the collection of a specifric version of OS and installed software).

Re: float representation on FreeBSD 10.1-RELEASE-p10

Posted: Tue Oct 27, 2015 2:52 pm
by rickyboy
Hey Kirill,

It's the same story on my employer's Windoze machine. It looks like the usual FP "noise" I see when sometimes I do FP arithmetic, regardless of language or OS; so, I'm almost sure it's an "FP thing" (but I don't know why we are seeing this in the newLISP float call).

BTW, +1 for OpenBSD mention. :)

Re: float representation on FreeBSD 10.1-RELEASE-p10

Posted: Tue Oct 27, 2015 3:14 pm
by Kirill
Well, that didn't happen earlier. I became aware of the issue when my SLA calculator became "broken".

Could the issue be caused by this change in 10.6.0?
The pretty-print default float setting has been changed to "%1.15g"

Re: float representation on FreeBSD 10.1-RELEASE-p10

Posted: Tue Oct 27, 2015 3:22 pm
by Kirill
And here was the "fix" for me for now:

Code: Select all

(define (format-sla sla)
  (trim (trim (format "%f" sla) "0") "."))

Re: float representation on FreeBSD 10.1-RELEASE-p10

Posted: Tue Oct 27, 2015 4:51 pm
by rickyboy
Behavior change happened between 10.6.1 and 10.6.2.

Code: Select all

$ ./newlisp
newLISP v.10.6.1 64-bit on BSD IPv4/6, options: newlisp -h

> (float 99.1)
99.1
> (float 99.9)
99.9
>

Code: Select all

$ ./newlisp
newLISP v.10.6.2 64-bit on BSD IPv4/6, options: newlisp -h

> (float 99.1)
99.09999999999999
> (float 99.9)
99.90000000000001
>

Re: float representation on FreeBSD 10.1-RELEASE-p10

Posted: Tue Oct 27, 2015 6:56 pm
by Lutz
This is due to the default display format set using pretty-print. You can get back the old behaviour by setting to less precision:

Code: Select all

> (pretty-print)
(80 " " "%1.16g")
> (float 99.1)
99.09999999999999

; change default display format to less precision
> (pretty-print 80 " " "%1.9g")
(80 " " "%1.9g")

> (float 99.1)
99.1
> (float 99.9)
99.9
>
This could be changed back, not sure what the general opinion about this is? For interactive work, you get a more regular display, showing each float in the same precision, but it is also confusing for the examples shown.

Re: float representation on FreeBSD 10.1-RELEASE-p10

Posted: Wed Oct 28, 2015 12:40 pm
by Kirill
Thanks, Lutz! I had a feeling it had to do with (pretty-print) default change, but didn't try to figure out what was the default before the change, so that I could restore it.