I was reading How to Design Programs and in the Exercise 2.1.1, I am to:
Find out whether DrScheme has operations for squaring a number; for computing the sine of an angle; and for determining the maximum of two numbers. -- sec. 2.2, ex 2.1.1
My code is:
(sin (/ 5 3))
(sqr 12)
(max (sin (/ 5 3)) (sqr 12))
And the result when I ran the program is:
#i0.9954079577517649
144
#i144.0
I am confused at the last expression where it get's the maximum of #i0.9954079577517649
and 144
. Shouldn't the answer be 144
or 144.0
instead of #i144.0
?
Scheme will give you an inexact number if either of the inputs to
max
(or other operations for that matter) are inexact.The standards document, R5RS, has this to say in section
6.2.5 Numerical operations
when discussingmin
andmax
:Now there's possibly a case to be made that
144
is very much greater than0.9954079577517649
but it would depend of the level of inaccuracy in that latter number. If the inaccuracy is on the order of a billion percent, it may well be much greater than144
:-)Section
6.2.2 Exactness
of that standard also has this:The
0.99
-ish number is inexact because sine and many other trigonometric functions are inherently inexact operations. The result of themax
is inexact because it has inexact inputs.