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:
parent
0ede27e927
commit
f1f9c11a04
2 changed files with 10 additions and 2 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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.)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue