float representation on FreeBSD 10.1-RELEASE-p10

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
Kirill
Posts: 90
Joined: Wed Oct 31, 2007 1:21 pm

float representation on FreeBSD 10.1-RELEASE-p10

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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: float representation on FreeBSD 10.1-RELEASE-p10

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

Kirill
Posts: 90
Joined: Wed Oct 31, 2007 1:21 pm

Re: float representation on FreeBSD 10.1-RELEASE-p10

Post 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"

Kirill
Posts: 90
Joined: Wed Oct 31, 2007 1:21 pm

Re: float representation on FreeBSD 10.1-RELEASE-p10

Post by Kirill »

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

Code: Select all

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

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: float representation on FreeBSD 10.1-RELEASE-p10

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: float representation on FreeBSD 10.1-RELEASE-p10

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

Kirill
Posts: 90
Joined: Wed Oct 31, 2007 1:21 pm

Re: float representation on FreeBSD 10.1-RELEASE-p10

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

Locked