float representation on FreeBSD 10.1-RELEASE-p10

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?

float representation on FreeBSD 10.1-RELEASE-p10

Postby Kirill » Tue Oct 27, 2015 11:29 am

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).
Kirill
 
Posts: 75
Joined: Wed Oct 31, 2007 1:21 pm

Re: float representation on FreeBSD 10.1-RELEASE-p10

Postby rickyboy » Tue Oct 27, 2015 2:52 pm

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)
rickyboy
 
Posts: 554
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: float representation on FreeBSD 10.1-RELEASE-p10

Postby Kirill » Tue Oct 27, 2015 3:14 pm

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: 75
Joined: Wed Oct 31, 2007 1:21 pm

Re: float representation on FreeBSD 10.1-RELEASE-p10

Postby Kirill » Tue Oct 27, 2015 3:22 pm

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

Code: Select all
(define (format-sla sla)
  (trim (trim (format "%f" sla) "0") "."))
Kirill
 
Posts: 75
Joined: Wed Oct 31, 2007 1:21 pm

Re: float representation on FreeBSD 10.1-RELEASE-p10

Postby rickyboy » Tue Oct 27, 2015 4:51 pm

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)
rickyboy
 
Posts: 554
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: float representation on FreeBSD 10.1-RELEASE-p10

Postby Lutz » Tue Oct 27, 2015 6:56 pm

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.
Lutz
 
Posts: 5258
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

Re: float representation on FreeBSD 10.1-RELEASE-p10

Postby Kirill » Wed Oct 28, 2015 12:40 pm

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.
Kirill
 
Posts: 75
Joined: Wed Oct 31, 2007 1:21 pm


Return to newLISP and the O.S.

Who is online

Users browsing this forum: No registered users and 2 guests

cron