A number literal has more precision than a double holds

tx0/ts:loss-of-precisiondefaultwarningbug

What it finds

9007199254740993 or 0.1000000000000000000001: a number literal with more precision than a double holds is rounded when the program is read, so the value used is not the one written.

A literal loses precision when its significant digits differ from those of the double it rounds to, printed with as many digits: 0.1 is fine, because the nearest double prints as 0.1 at one digit, while 9007199254740993 rounds to 9007199254740992. Literals in other radixes lose precision when they have more than 53 significant bits. Literals too large for a double, which become Infinity, and nonzero ones too small, which become 0, lose all of it. Fractions written with more than 17 significant digits, as mathematical constants often are, cannot be meant exactly and round to the nearest double as intended, so they are not reported; integers are, since an integer that changes is usually an identifier that no longer matches.

From the rule's source, loss_of_precision.rs.

Example from the rule's tests
const id = 9007199254740993;tx0 reports: 9007199254740993 cannot be represented exactlyconst big = 12345678901234567890;tx0 reports: cannot be represented exactlyconst hex = 0x20000000000001;tx0 reports: cannot be represented exactlyconst huge = 1e400;tx0 reports: cannot be represented exactlyconst fine = [0.1, 1.5e10, 9007199254740992, 0x1fffffffffffff, 1_000_000, 5e-324, 1e21];const constant = 0.0640568928626056260850430826247450385909;const bigint = 9007199254740993n;
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:loss-of-precision" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:loss-of-precision] reason="..."

tx0 explain tx0/ts:loss-of-precision shows the same in the terminal. Found a false positive? Report it.