Skip to main content

CRR0024 - Increase precision with a built-in constant or call

This analyzer detects the usage of numerical literals that can be replaced with a more precise built-in constant or function call. For instance, this analyzer will detect numeric literals that are close to the 𝜋 value.

double S(double r) => 3.14159265359 * r * r; // CRR0024

Consider changing the literal to the Math.Pi constant. This will improve the code readability and the method’s precision.

double S(double r) => Math.Pi * r * r; // CRR0024

Note

In the example given above, you can also apply the Convert to Math.Pow call refactoring.