Clarify Dec range and decimal places in docs

Also remove extra numbers from float result for 0.1 + 0.2.
Floats only have 16 decimal places of precision and the rest generally is not printed.
This commit is contained in:
Brendan Hansknecht 2023-09-15 14:57:34 -07:00
parent 4f0dbf4e03
commit 562c6b4a8c
No known key found for this signature in database
GPG key ID: 0EA784685083E75B

View file

@ -348,8 +348,8 @@ Int range : Num (Integer range)
## ##
## Roc fractions come in two flavors: fixed-point base-10 and floating-point base-2. ## Roc fractions come in two flavors: fixed-point base-10 and floating-point base-2.
## ##
## * [Dec] is a 128-bit [fixed-point](https://en.wikipedia.org/wiki/Fixed-point_arithmetic) base-10 number. It's a great default choice, especially when precision is important - for example when representing currency. With [Dec], 0.1 + 0.2 returns 0.3. ## * [Dec] is a 128-bit [fixed-point](https://en.wikipedia.org/wiki/Fixed-point_arithmetic) base-10 number. It's a great default choice, especially when precision is important - for example when representing currency. With [Dec], `0.1 + 0.2` returns `0.3`. [Dec] has 18 decimal places of precision and a range from `-170_141_183_460_469_231_731.687303715884105728` to `170_141_183_460_469_231_731.687303715884105727`.
## * [F64] and [F32] are [floating-point](https://en.wikipedia.org/wiki/Floating-point_arithmetic) base-2 numbers. They sacrifice precision for lower memory usage and improved performance on some operations. This makes them a good fit for representing graphical coordinates. With [F64], 0.1 + 0.2 returns 0.3000000000000000444089209850062616169452667236328125. ## * [F64] and [F32] are [floating-point](https://en.wikipedia.org/wiki/Floating-point_arithmetic) base-2 numbers. They sacrifice precision for lower memory usage and improved performance on some operations. This makes them a good fit for representing graphical coordinates. With [F64], `0.1 + 0.2` returns `0.30000000000000004`.
## ##
## If you don't specify a type, Roc will default to using [Dec] because it's ## If you don't specify a type, Roc will default to using [Dec] because it's
## the least error-prone overall. For example, suppose you write this: ## the least error-prone overall. For example, suppose you write this: