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.) +}