feat: use more precise pi

with pretty_eval, I still get:
-9.194801691 * 10^-618

but at least that's more accurate than the prior:
1.224646799 * 10^-16
This commit is contained in:
electria 2026-10-20 21:27:40 -07:00
commit f1f9c11a04
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 10 additions and 2 deletions

View file

@ -1,7 +1,10 @@
use core::f64; use core::f64;
use std::str::FromStr; use std::str::FromStr;
use rug::{Float, float::ParseFloatError}; use rug::{
Float,
float::{self, ParseFloatError},
};
use crate::nodes::{Function, Node, Nodes, Operator}; use crate::nodes::{Function, Node, Nodes, Operator};
@ -10,7 +13,7 @@ impl Node {
Ok(match s { Ok(match s {
"c" => Self::from(299_792_458), "c" => Self::from(299_792_458),
"A" => Self::from(6.02214076e23), "A" => Self::from(6.02214076e23),
"pi" | "π" => Self::from(f64::consts::PI), "pi" | "π" => Self::from(float::Constant::Pi),
// Planck's constant, in J*s (joule-seconds) // Planck's constant, in J*s (joule-seconds)
"h" => Self::from(6.62607015e-34), "h" => Self::from(6.62607015e-34),
"e" => Self::from(f64::consts::E), "e" => Self::from(f64::consts::E),

View file

@ -51,3 +51,8 @@ fn constant_implicit_mult() {
assert_eq!(eval("2pi"), 6.283185307179586); assert_eq!(eval("2pi"), 6.283185307179586);
assert_eq!(eval("pi2"), 6.283185307179586); assert_eq!(eval("pi2"), 6.283185307179586);
} }
#[test]
fn pi_precision() {
assert_eq!(eval("sin(pi)"), 0.)
}