Hard-coded approximation of a standard math constant

ID

rust.correctness.approx_constant

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Numeric Literal

Language

Rust

Description

This literal is a truncated approximation of a constant that the standard library already defines exactly for the target type. Use the matching item from std::f64::consts (or std::f32::consts) so the value keeps full precision.

Rationale

This literal is a truncated approximation of a constant that the standard library already defines exactly for the target type. Use the matching item from std::f64::consts (or std::f32::consts) so the value keeps full precision.

The following code illustrates the pattern detected by this rule:

use std::f64::consts;
pub fn area(r: f64) -> f64 {
    // FLAGGED: Hard-coded approximation of a standard math constant
    let pi = 3.14159;
    pi * r * r
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved