From f1f9c11a046b0d7fb2a25e80ccce8d7d7f73dced Mon Sep 17 00:00:00 2001 From: electria Date: Tue, 20 Oct 2026 21:27:40 -0700 Subject: [PATCH] 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 --- src/nodes/parse.rs | 7 +++++-- src/nodes/tests.rs | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/nodes/parse.rs b/src/nodes/parse.rs index 96d4236..e3da6e6 100644 --- a/src/nodes/parse.rs +++ b/src/nodes/parse.rs @@ -1,7 +1,10 @@ use core::f64; use std::str::FromStr; -use rug::{Float, float::ParseFloatError}; +use rug::{ + Float, + float::{self, ParseFloatError}, +}; use crate::nodes::{Function, Node, Nodes, Operator}; @@ -10,7 +13,7 @@ impl Node { Ok(match s { "c" => Self::from(299_792_458), "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) "h" => Self::from(6.62607015e-34), "e" => Self::from(f64::consts::E), diff --git a/src/nodes/tests.rs b/src/nodes/tests.rs index 15b6c21..2f22d8a 100644 --- a/src/nodes/tests.rs +++ b/src/nodes/tests.rs @@ -51,3 +51,8 @@ fn constant_implicit_mult() { assert_eq!(eval("2pi"), 6.283185307179586); assert_eq!(eval("pi2"), 6.283185307179586); } + +#[test] +fn pi_precision() { + assert_eq!(eval("sin(pi)"), 0.) +}