algebraic operations coercion rules for results

Discussion of Scheme and Racket

algebraic operations coercion rules for results

Postby 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
reventlov2035
 
Posts: 1
Joined: Sun Apr 07, 2019 8:29 am

Return to Scheme

Who is online

Users browsing this forum: No registered users and 3 guests

cron