mirror of
https://github.com/nushell/nushell.git
synced 2025-04-17 17:58:18 +02:00
Add math tau
(#7408)
# Description Prompted by https://discord.com/channels/601130461678272522/615329862395101194/1050693116501426216 # User-Facing Changes New command `math tau` and endless agony whether to use `math pi` or `math tau` # Tests + Formatting Example test
This commit is contained in:
parent
b938adefaa
commit
b4529a20e8
@ -419,6 +419,7 @@ pub fn create_default_context() -> EngineState {
|
|||||||
MathArcCosH,
|
MathArcCosH,
|
||||||
MathArcTanH,
|
MathArcTanH,
|
||||||
MathPi,
|
MathPi,
|
||||||
|
MathTau,
|
||||||
MathEuler,
|
MathEuler,
|
||||||
MathLn,
|
MathLn,
|
||||||
};
|
};
|
||||||
|
@ -29,6 +29,7 @@ mod stddev;
|
|||||||
mod sum;
|
mod sum;
|
||||||
mod tan;
|
mod tan;
|
||||||
mod tanh;
|
mod tanh;
|
||||||
|
mod tau;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod variance;
|
mod variance;
|
||||||
|
|
||||||
@ -65,5 +66,6 @@ pub use arctanh::SubCommand as MathArcTanH;
|
|||||||
|
|
||||||
pub use euler::SubCommand as MathEuler;
|
pub use euler::SubCommand as MathEuler;
|
||||||
pub use pi::SubCommand as MathPi;
|
pub use pi::SubCommand as MathPi;
|
||||||
|
pub use tau::SubCommand as MathTau;
|
||||||
|
|
||||||
pub use ln::SubCommand as MathLn;
|
pub use ln::SubCommand as MathLn;
|
||||||
|
61
crates/nu-command/src/math/tau.rs
Normal file
61
crates/nu-command/src/math/tau.rs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
use nu_protocol::ast::Call;
|
||||||
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
|
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Type, Value};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct SubCommand;
|
||||||
|
|
||||||
|
impl Command for SubCommand {
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"math tau"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> Signature {
|
||||||
|
Signature::build("math tau")
|
||||||
|
.input_output_types(vec![(Type::Any, Type::Float)])
|
||||||
|
.category(Category::Math)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage(&self) -> &str {
|
||||||
|
"Returns the mathematical constant τ."
|
||||||
|
}
|
||||||
|
|
||||||
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
|
vec!["trigonometry", "constant"]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::approx_constant)]
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![Example {
|
||||||
|
example: "(math tau) / 2",
|
||||||
|
description: "Compare π and τ",
|
||||||
|
result: Some(Value::test_float(std::f64::consts::PI)),
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
_engine_state: &EngineState,
|
||||||
|
_stack: &mut Stack,
|
||||||
|
call: &Call,
|
||||||
|
_input: PipelineData,
|
||||||
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
|
Ok(Value::Float {
|
||||||
|
val: std::f64::consts::TAU,
|
||||||
|
span: call.head,
|
||||||
|
}
|
||||||
|
.into_pipeline_data())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_examples() {
|
||||||
|
use crate::test_examples;
|
||||||
|
|
||||||
|
test_examples(SubCommand {})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user