Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

srfi 1 test failing on OS X #329

Closed
saysjonathan opened this issue Jan 31, 2016 · 7 comments
Closed

srfi 1 test failing on OS X #329

saysjonathan opened this issue Jan 31, 2016 · 7 comments

Comments

@saysjonathan
Copy link

$ make test-srfi
<snip>
case 13 FAIL: (iota 5 0 -0.1)
   expected (0 -0.1 -0.2 -0.3 -0.4) but got (0 -0.1 -0.2 -0.30000000000000007 -0.4)
<snip>
 FAIL: (iota 5 0 -0.1)
   expected (0 -0.1 -0.2 -0.3 -0.4) but got (0 -0.1 -0.2 -0.30000000000000007 -0.4)
@KeenS
Copy link
Member

KeenS commented Feb 1, 2016

Verified. It is basically precision problem but there might be something we can do for

@saysjonathan
Copy link
Author

Precision issues appear to transcend OS. Verified on Linux:

> (+ 0.1 (+ 0.1 (+ 0.1)))
0.30000000000000007

$ uname -sr
Linux 3.10.0-042stab108.5

@nyuichi
Copy link
Member

nyuichi commented Feb 1, 2016

It seems we cannot fix this issue. The test case should be changed.

@saysjonathan
Copy link
Author

What's preventing this from being fixed?

@nyuichi
Copy link
Member

nyuichi commented Feb 1, 2016

Picrin doesn't have internal representation of exact rational number so 0.1 is implicitly converted to double. We cannot avoid this kind of error as long as FPU computes in binary. Meanwhile, I got a similar result running python:

$ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.1 + 0.1 + 0.1
0.30000000000000004
>>> 

@saysjonathan
Copy link
Author

Makes perfect sense.

Same for Ruby:

irb(main):001:0> 0.1 + 0.1 + 0.1
=> 0.30000000000000004

and Haskell:

Prelude> 0.1 + 0.1 + 0.1
0.30000000000000004

👍 for changing the test case.

@saysjonathan
Copy link
Author

In case anyone is interested, Chibi and Guile both work:

$ chibi-scheme
> (* 0.1 3)
0.3
> (* 0.1 12)
1.2

$ guile
guile> (* 0.1 3)
0.3
guile> (* 0.1 12)
1.2

@nyuichi nyuichi closed this as completed Feb 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants