[plt-scheme] question about Scheme numbers

From: Peter Horst (phorst at speakeasy.net)
Date: Sat May 13 00:21:47 EDT 2006

OK, so I've got (under Dr. Scheme 3.01 "Textual"):

(define square
  (lambda (n)
    (* n n)))

(define hypotenuse
  (lambda (adjacent opposite)
    (sqrt (+ (square adjacent) (square opposite)))))

Calculating the hypotenuse of a 30-60-90 right triangle I get:

 > (hypo (sqrt 3) 1)
2.0

but

 > (square (sqrt 3))
2.9999999999999996

How come?

Thank you!


Posted on the users mailing list.