Skip to content

Commit

Permalink
cratification: part II of the math commands to nu-cmd-extra (#9657)
Browse files Browse the repository at this point in the history
The following math commands are being moved to nu-cmd-extra

* cos
* cosh
* egamma
* phi
* pi
* sin
* sinh
* tan
* tanh
* tau

For now I think we have most of the obvious commands moved over based on

@sholderbach this should cover moving the "high school" commands..

>>Yeah I think this rough separation into "high school" math in extra
and "middle school"/"programmer" math in the core makes a ton of sense.

And to reference the @fdncred list from
#9647 (comment)
  • Loading branch information
stormasm committed Jul 11, 2023
1 parent e10d84b commit 942c66a
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 34 deletions.
4 changes: 4 additions & 0 deletions crates/nu-cmd-extra/src/example_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod test_examples {
check_example_input_and_output_types_match_command_signature,
};

use crate::MathPi;
use nu_protocol::{
engine::{Command, EngineState, StateWorkingSet},
Type,
Expand Down Expand Up @@ -63,6 +64,9 @@ mod test_examples {

working_set.add_decl(Box::new(nu_command::Enumerate));
working_set.add_decl(Box::new(nu_cmd_lang::If));
// math commands
working_set.add_decl(Box::new(MathPi));
working_set.add_decl(Box::new(nu_command::MathRound));

// Adding the command that is being tested to the working set
working_set.add_decl(cmd);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions crates/nu-cmd-extra/src/extra/math/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
mod cos;
mod cosh;
mod sin;
mod sinh;
mod tan;
mod tanh;

mod egamma;
mod phi;
mod pi;
mod tau;

mod arccos;
mod arccosh;
mod arcsin;
mod arcsinh;
mod arctan;
mod arctanh;

pub use cos::SubCommand as MathCos;
pub use cosh::SubCommand as MathCosH;
pub use sin::SubCommand as MathSin;
pub use sinh::SubCommand as MathSinH;
pub use tan::SubCommand as MathTan;
pub use tanh::SubCommand as MathTanH;

pub use egamma::SubCommand as MathEulerGamma;
pub use phi::SubCommand as MathPhi;
pub use pi::SubCommand as MathPi;
pub use tau::SubCommand as MathTau;

pub use arccos::SubCommand as MathArcCos;
pub use arccosh::SubCommand as MathArcCosH;
pub use arcsin::SubCommand as MathArcSin;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 21 additions & 1 deletion crates/nu-cmd-extra/src/extra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ pub use bits::BitsShl;
pub use bits::BitsShr;
pub use bits::BitsXor;

pub use math::MathCos;
pub use math::MathCosH;
pub use math::MathSin;
pub use math::MathSinH;
pub use math::MathTan;
pub use math::MathTanH;

pub use math::MathEulerGamma;
pub use math::MathPhi;
pub use math::MathPi;
pub use math::MathTau;

pub use math::MathArcCos;
pub use math::MathArcCosH;
pub use math::MathArcSin;
Expand Down Expand Up @@ -113,7 +125,15 @@ pub fn add_extra_command_context(mut engine_state: EngineState) -> EngineState {
MathArcTan,
MathArcSinH,
MathArcCosH,
MathArcTanH
MathArcTanH,
MathSin,
MathCos,
MathTan,
MathSinH,
MathCosH,
MathTanH,
MathPi,
MathTau
};

working_set.render()
Expand Down
8 changes: 0 additions & 8 deletions crates/nu-command/src/default_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,6 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
MathStddev,
MathSum,
MathVariance,
MathSin,
MathCos,
MathTan,
MathSinH,
MathCosH,
MathTanH,
MathPi,
MathTau,
MathEuler,
MathExp,
MathLn,
Expand Down
7 changes: 3 additions & 4 deletions crates/nu-command/src/example_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pub fn test_examples(cmd: impl Command + 'static) {
#[cfg(test)]
mod test_examples {
use super::super::{
Ansi, Date, Enumerate, Flatten, From, Get, Into, IntoString, Math, MathEuler, MathPi,
MathRound, ParEach, Path, PathParse, Random, Sort, SortBy, Split, SplitColumn, SplitRow,
Str, StrJoin, StrLength, StrReplace, Update, Url, Values, Wrap,
Ansi, Date, Enumerate, Flatten, From, Get, Into, IntoString, Math, MathEuler, MathRound,
ParEach, Path, PathParse, Random, Sort, SortBy, Split, SplitColumn, SplitRow, Str, StrJoin,
StrLength, StrReplace, Update, Url, Values, Wrap,
};
use crate::{Each, To};
use nu_cmd_lang::example_support::{
Expand Down Expand Up @@ -80,7 +80,6 @@ mod test_examples {
working_set.add_decl(Box::new(Let));
working_set.add_decl(Box::new(Math));
working_set.add_decl(Box::new(MathEuler));
working_set.add_decl(Box::new(MathPi));
working_set.add_decl(Box::new(MathRound));
working_set.add_decl(Box::new(Mut));
working_set.add_decl(Box::new(Path));
Expand Down
21 changes: 0 additions & 21 deletions crates/nu-command/src/math/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
mod abs;
mod avg;
mod ceil;
mod cos;
mod cosh;
mod egamma;
mod euler;
mod exp;
mod floor;
Expand All @@ -14,19 +11,12 @@ mod max;
mod median;
mod min;
mod mode;
mod phi;
mod pi;
mod product;
mod reducers;
mod round;
mod sin;
mod sinh;
mod sqrt;
mod stddev;
mod sum;
mod tan;
mod tanh;
mod tau;
mod utils;
mod variance;

Expand All @@ -46,18 +36,7 @@ pub use stddev::SubCommand as MathStddev;
pub use sum::SubCommand as MathSum;
pub use variance::SubCommand as MathVariance;

pub use cos::SubCommand as MathCos;
pub use cosh::SubCommand as MathCosH;
pub use sin::SubCommand as MathSin;
pub use sinh::SubCommand as MathSinH;
pub use tan::SubCommand as MathTan;
pub use tanh::SubCommand as MathTanH;

pub use egamma::SubCommand as MathEulerGamma;
pub use euler::SubCommand as MathEuler;
pub use phi::SubCommand as MathPhi;
pub use pi::SubCommand as MathPi;
pub use tau::SubCommand as MathTau;

pub use self::log::SubCommand as MathLog;
pub use exp::SubCommand as MathExp;
Expand Down

0 comments on commit 942c66a

Please sign in to comment.