Pi or e is written as a literal approximation instead of Math.PI or Math.E
What it finds
3.14159 and 2.718 are approximations of π and e that are less precise than the double constants Math.PI and Math.E, and the error grows in every computation that uses them.
Reported is a floating-point literal of at least three decimal places that agrees with π or e up to its last digit but is not the full constant.
From the rule's source, approximate_math_constant.rs.
class Circle { double area(double r) { double a = 3.14159 * r * r;tx0 reports: approximates Math.PI double e = 2.718;tx0 reports: approximates Math.E double b = 3.15; return a + e + b; }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:approximate-math-constant" = "warning"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/java:approximate-math-constant] reason="..."tx0 explain tx0/java:approximate-math-constant shows the same in the terminal. Found a false positive? Report it.