float representation on FreeBSD 10.1-RELEASE-p10

Started by Kirill, October 27, 2015, 04:29:33 AM

Previous topic - Next topic

Kirill

newLISP v.10.6.2 on FreeBSD 10.1 (on NearlyFreeSpeech) represents floats in some trange way:


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:


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).

rickyboy

#1
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.  :)
(λx. x x) (λx. x x)

Kirill

#2
Well, that didn't happen earlier. I became aware of the issue when my http://uptime.is/">SLA calculator became "broken".



Could the issue be caused by this change in 10.6.0?


QuoteThe pretty-print default float setting has been changed to "%1.15g"

Kirill

#3
And here was the "fix" for me for now:


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

rickyboy

#4
Behavior change happened between 10.6.1 and 10.6.2.


$ ./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
>


$ ./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
>
(λx. x x) (λx. x x)

Lutz

#5
This is due to the default display format set using pretty-print. You can get back the old behaviour by setting to less precision:


> (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.

Kirill

#6
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.