slack1
2017-12-26 20:02:12

When the Racket guide says that integers are “exact”, does that mean so as long as my operations are closed around integers, then I don’t have to worry about that floating point correction stuff?


lexi.lambda
2017-12-26 20:03:27

If you stick to exact operations on exact inputs, then yes, there will be no loss of precision, unlike floating-point arithmetic.


slack1
2017-12-26 20:04:12

whoa that’s pretty cool


lexi.lambda
2017-12-26 20:04:36

Basic numeric operations like addition, subtraction, multiplication, division, and exponentiation will preserve exactness, but some operations will not (like sqrt, since Racket does not have any exact representation of irrational numbers).


lexi.lambda
2017-12-26 20:04:54

Likewise, pi and e are inexact numbers, and any computation using them will therefore become inexact.


slack1
2017-12-26 20:05:03

i see


lexi.lambda
2017-12-26 20:06:31

(Floating-point numbers are also much faster than exact rationals, since your computer has hardware specifically for the purpose of making floating-point operations fast.)


lexi.lambda
2017-12-26 20:07:16

(And floating-point numbers also have the advantage of taking up a constant amount of memory, whereas exact numbers are arbitrary-precision, so arbitrarily large numbers can take up arbitrarily-large amounts of memory.)


slack1
2017-12-26 20:07:31

Yeah but I know there’s some machinery involved in working with floating points


slack1
2017-12-26 20:07:37

Like you have to compare to an epsilon or something


lexi.lambda
2017-12-26 20:08:57

Yes. Racket’s exact numbers are like BigInteger and BigDecimal in Java, if you are at all familiar with that.