Odin is a strongly typed language, and it follows for the most part int64, int32, and their float counter parts.
Summary Table
| Type | Precision Limit (Exact) | What happens after? |
|---|---|---|
| i64/u64 | ~18.4 Quintillion | It wraps/overflows |
| f64 | ~ 9 Quadrillion | It skips odd numbers, then larger gaps. |
| f32 | ~ 16.7 Million | It connot represent the next whole number. |
1. Integers (Exact Precision)
Integers in Odin have perfect precision until they hit their maximum capacity. Once they exceed that limit, they will "wrap around" also known has overflow rather than lose precision.
The largest standard integer is u64 (unsigned 64-bit).
- Max Value:
-1 - The Number: 18,446,744,073,709,551,615
- When to worry: The moment you add
1to that number, it resets to0. If you need numbers larger than this, you would need to use aBigIntlibrary.
2. Floating-Point Numbers (The "Drift')
Both f32 and f64 have a lot less precision than Integers do to the . taking up space in the 32 or 64bit space(The mantissa and the scale).
f32 (Single Precision)
You start losing "integer precision"[1] after 16,777,216(
- The behavior: if you have an
f32equal to 16,777,216 and you add 1, the result remains 16,777,216. The "gap" between representable numbers becomes larger than 1.
f64 (Double Precision / Default)
This is what Odin uses for literal decimals (e.g. x := 1.0). You lose integer precision after 9,007,199,254,740,992 (
- The "Rule of Thumb": If your whole numbers stay below 9 quadrillion, an
f64will behave exactly like an integer.
What to do if you need to bigger?
There is a library at core:math/big that handles that.
The ability to represent every while number exactly. ↩︎