"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Friday, June 16, 2006

Exact Math

The binary search controversy has improperly gone from the definition of numbers in poorly designed languages to the "static vs. dynamic" debate, which has no bearing on this topic. Then the question came up about floating point and why even Smalltalk accepts that 1e16 + 1 is equal to 1e16 when using a floating point (i.e. inexact) representation of integers.

The numerical tower in Scheme explicitly defines what number representations and procedures deal with exact or with inexact math. You get to choose, for instance based on whether you need speed or accuracy.

> (+ 2/3 1/3)
1
> exact->inexact
#inexact>
> (exact->inexact 1/3)
.3333333333333333
> (= (+ 1 10000000000000000) (+ 1 (exact->inexact 10000000000000000)))
#f
> (= 1e16 (exact->inexact 10000000000000000))
#t

No comments:

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.