Back to Devexpress

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

coderushforroslyn-118243-static-code-analysis-analyzers-library-crr0024-increase-precision-with-a-built-in-constant-or-call.md

latest1.2 KB
Original Source

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

  • Feb 28, 2025

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.

csharp
double S(double r) => 3.14159265359 * r * r; // CRR0024
vb
Function S(r As Double) As Double
    Return 3.14159265359 * r * r ' CRR0024
End Function

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

csharp
double S(double r) => Math.Pi * r * r; // CRR0024
vb
Function S(r As Double) As Double
    Return Math.Pi * r * r ' CRR0024
End Function

Note

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

See Also

Suppress Analyzers