refactor: use compiler builtin constant for pi

as per clippy lint
This commit is contained in:
electria 2026-07-16 10:53:49 -07:00
commit cf8d218b11
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 4 additions and 2 deletions

View file

@ -1,3 +1,4 @@
use core::f64;
use std::str::FromStr;
use rug::{Float, float::ParseFloatError, ops::CompleteRound};
@ -9,7 +10,7 @@ impl Node {
Ok(match s {
"c" => Self::Number(Float::with_val(PREC, 299_792_458)),
"A" => Self::Number(Float::with_val(PREC, 6.02214076e23)),
"pi" => Self::Number(Float::with_val(PREC, 3.1415926536)),
"pi" => Self::Number(Float::with_val(PREC, f64::consts::PI)),
_ => Self::Function(s.parse()?),
})
}

View file

@ -1,3 +1,4 @@
use core::f64;
use std::str::FromStr;
use rug::Float;
@ -24,7 +25,7 @@ fn constants() {
);
assert_eq!(
Nodes::from_str("pi").unwrap().evaluate().to_f64(),
3.1415926536
f64::consts::PI
);
}