algebraic operations coercion rules for results

Discussion of Scheme and Racket
Post Reply
reventlov2035
Posts: 1
Joined: Sun Apr 07, 2019 8:29 am

algebraic operations coercion rules for results

Post by reventlov2035 » Sun Apr 07, 2019 9:19 am

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

Code: Select all

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

Code: Select all

> 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

bogdan
Posts: 2
Joined: Tue Aug 27, 2019 11:35 pm
Location: Cluj-Napoca, Romania
Contact:

Re: algebraic operations coercion rules for results

Post by bogdan » Thu Sep 12, 2019 12:37 am

where can I find the coercion rules for algebraic/arithmetic operations ?
I would look at R5RS. If it isn't specified, then it's up to you/implementation specific.

Post Reply