Skip to content

Commit

Permalink
temp solution until constants are part of std: rust-lang/rust#103883
Browse files Browse the repository at this point in the history
  • Loading branch information
simdimdim committed May 30, 2023
1 parent 0329890 commit 5f36061
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crates/nu-command/src/math/egamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
};

/// The Euler-Mascheroni constant (γ)
pub const EGAMMA: f64 = 0.577215664901532860606512090082402431_f64;

#[derive(Clone)]
pub struct SubCommand;

Expand Down Expand Up @@ -42,7 +45,8 @@ impl Command for SubCommand {
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Ok(Value::float(std::f64::consts::EGAMMA, call.head).into_pipeline_data())
// TODO: replace with std::f64::consts::EGAMMA when available https://github.com/rust-lang/rust/issues/103883
Ok(Value::float(EGAMMA, call.head).into_pipeline_data())
}
}

Expand Down
5 changes: 4 additions & 1 deletion crates/nu-command/src/math/phi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use nu_protocol::engine::{Command, EngineState, Stack};
use nu_protocol::{
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Type, Value,
};
/// The golden ratio (φ)
pub const PHI: f64 = 1.618033988749894848204586834365638118_f64;

#[derive(Clone)]
pub struct SubCommand;
Expand Down Expand Up @@ -42,7 +44,8 @@ impl Command for SubCommand {
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Ok(Value::float(std::f64::consts::PHI, call.head).into_pipeline_data())
// TODO: replace with std::f64::consts::PHI when available https://github.com/rust-lang/rust/issues/103883
Ok(Value::float(PHI, call.head).into_pipeline_data())
}
}

Expand Down

0 comments on commit 5f36061

Please sign in to comment.