Home / Docs / Diagnostics

U2032: A float literal other than zero, or a float range, as a pattern

Release v0.4.0

A when arm or an is test does not match an F64 against a float literal (spec/29, ADR 0114). A computed float rarely equals a literal exactly, and the test hides which equality is meant: the identity of ==, under which -0.0 and 0.0 differ, or IEEE equality. Compare in an if, with == for identity or an IEEE method such as x.ieee_eq(other: 0.5).

The repair at a glance

src/demo.unadiff
  module demo

- pub is_half(x: F64) -> Bool = x is 0.5
+ pub is_half(x: F64) -> Bool = x == 0.5

Failing example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"
src/demo.unauna
module demo

pub is_half(x: F64) -> Bool = x is 0.5

Fixed example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"
src/demo.unauna
module demo

pub is_half(x: F64) -> Bool = x == 0.5