Home / Docs / Diagnostics
U2031: A float literal rounds to an infinity, or is not zero and rounds to zero
Release v0.4.0
A float literal would round to an infinity, or is not zero and would round to zero.
Why Una rejects it
A float literal denotes the F64 nearest its exact decimal value (spec/29, ADR 0114).
- A literal beyond the largest finite
F64,1.7976931348623157e308, would round to an infinity. - A literal that is not zero but below half the smallest positive
F64,5.0e-324, would round to zero.
Either way the program would compute with a value other than the one written, so the checker refuses the literal.
A literal that rounds to a subnormal value is accepted.
How to fix it
- Write
infinity()when an infinity is meant. - Write
0.0when zero is meant. - Or write a value in range.
The repair at a glance
src/demo.una
module demo
- pub tiny() -> F64 = 1.0e-400
+ pub tiny() -> F64 = 0.0Failing example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"src/demo.una
module demo
pub tiny() -> F64 = 1.0e-400Fixed example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"src/demo.una
module demo
pub tiny() -> F64 = 0.0