This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

algebraic operations coercion rules for results

1 post · 2317 views

since I feel that the best way to learn a language is to write an interpreter/compiler for it :mrgreen:
I am trying to write a simple scheme interpreter

where can I find the coercion rules for algebraic/arithmetic operations ?

a silly example of why I am asking the question
( + 0   0.01 )
( + 0   0.001 )
( + 0   0.0001 )
( + 0   0.00001 )

( + 1   0.01 )
( + 1   0.001 )
( + 1   0.0001 )
( + 1   0.00001 ) 
the result
> 0.01
> 0.001
> 1e-4
> 1e-5

> 1.01
> 1.001
> 1.0001
> 1.00001
is there a logic behind the switch to scientific notation for ( + 0 0.0001 )
or the coercion is only an implementation detail ?

cheers
G

PS
the above from chez scheme 9.5

even if with different magnitudes something similar happens at
https://repl.it/languages/scheme
BiwaScheme Interpreter version 0.6.4

( + 0 0.000001) ==> 0.000001
( + 0 0.0000001) ==> 1e-7