mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:45:45 +02:00
Add Tau constant (#2673)
Adds Tau constant using meval::Context. Also adds a test to match pi's. Note: Tau ends up not being more precise than 2*pi. Resolves: #2258
This commit is contained in:
@ -91,7 +91,9 @@ pub async fn eval(
|
||||
}
|
||||
|
||||
pub fn parse<T: Into<Tag>>(math_expression: &str, tag: T) -> Result<Value, String> {
|
||||
match meval::eval_str(math_expression) {
|
||||
let mut ctx = meval::Context::new();
|
||||
ctx.var("tau", std::f64::consts::TAU);
|
||||
match meval::eval_str_with_context(math_expression, &ctx) {
|
||||
Ok(num) if num.is_infinite() || num.is_nan() => Err("cannot represent result".to_string()),
|
||||
Ok(num) => Ok(UntaggedValue::from(Primitive::from(num)).into_value(tag)),
|
||||
Err(error) => Err(error.to_string().to_lowercase()),
|
||||
|
Reference in New Issue
Block a user