Home / Docs / Diagnostics
U2037: A decimal scale out of place
Release v0.4.0
In edition 0.5 (preview), a decimal scale is in a place where it would not fit.
Why Una rejects it
A Decimal[s] holds an exact number with s digits after the point, and its scale is part of the type (spec/29 §16, ADR 0120). The scale is an integer literal from 0 to 38. A value never loses a digit silently, so the checker refuses every place where a scale would not fit:
- a scale above 38, or a
Decimaltype without its scale in brackets; - a float literal with a nonzero digit beyond the scale it takes, such as
19.995as aDecimal[2], also as the other operand of+,-or*, where the literal takes that operand's scale and never widens it; - a literal whose coefficient would have more than 4,300 digits, the language's digit cap;
- a product whose scale, the sum of its operands' scales, is above 38;
widento a smaller scale, andrescaleorrescale_exactto a scale that is not smaller;- a scale argument,
scale:, that is not an integer literal.
How to fix it
- Give the literal its own type (
let fee: Decimal[3] = 0.005). - Write fewer digits.
- Rescale an operand first.
- Or use the method that matches the direction of the change:
widenadds digits,rescaledrops them with a written rounding mode.
The repair at a glance
src/demo.una
module demo
- pub price() -> Decimal[2] = 19.995
+ pub price() -> Decimal[3] = 19.995Failing example
ita.una
ita demo
version 0.1.0
edition 0.5ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.una
module demo
pub price() -> Decimal[2] = 19.995Fixed example
ita.una
ita demo
version 0.1.0
edition 0.5ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.una
module demo
pub price() -> Decimal[3] = 19.995