When this matters
Use exact integers and rationals when the mathematical result must stay exact. Introduce a real only when an inexact measurement or explicitly inexact operation is part of the problem.
See it run
LISPEX
(list (/ 1 3) (+ 1 2.0) (number->string -0.0))Observed result
OUTPUT
(1/3 3.0 "-0.0")Read the example
1/3 stays an exact reduced rational. Adding exact 1 to inexact 2.0 produces inexact 3.0. Rendering preserves the sign of negative zero, so number->string returns "-0.0".
How to reason about it
- Exact arithmetic stays exact;
+ - * /become inexact if any operand is inexact. Comparisons use exact mixed-number comparison. - No infinity or NaN value can enter the runtime; division by zero is E313 and non-finite production is E314.
- Finite real output is shortest round-trip, positional only, with a forced
.0and preserved-0.0.
Choose quickly
| Kind | Examples | Key rule |
|---|---|---|
| exact integer | 0, -12, 999999999999 | arbitrary precision |
| exact rational | 1/3, -5/2 | stored reduced with positive denominator |
| finite real | 2.0, -0.0, 0.125 | finite IEEE-754 and canonical positional output |
| mixed arithmetic | (+ 1 2.0) | one inexact operand makes arithmetic inexact |
| mixed comparison | (= 2 2.0) | compared mathematically without lossy coercion |
A common mistake
Complex numbers and platform-libm transcendentals are excluded.
Current boundaries
- Exact/inexact contagion for arithmetic must not be generalized to selection or comparison semantics.
Keep going
Numeric Procedures lists domains and signatures. Equality explains why numeric equality differs from exactness-sensitive equality.