From ec880155c7c36c6d2b3462f210e96782486093e5 Mon Sep 17 00:00:00 2001 From: Edwin Svensson Date: Sun, 30 May 2021 11:08:59 +0200 Subject: [PATCH] add math consts context --- src/context/mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/context/mod.rs b/src/context/mod.rs index ef27b6f..94fe055 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -163,3 +163,41 @@ macro_rules! context_map { .map(|_| context) }}; } + +/// Context with all f64::consts available by default. +/// Alternatively, specifiy constants with math_consts_context!(E, PI, TAU, ...) +/// Available constants can be found in the core::f64::consts module. +#[macro_export] +macro_rules! math_consts_context { + () => { + $crate::math_consts_context!( + PI, + TAU, + FRAC_PI_2, + FRAC_PI_3, + FRAC_PI_4, + FRAC_PI_6, + FRAC_PI_8, + FRAC_1_PI, + FRAC_2_PI, + FRAC_2_SQRT_PI, + SQRT_2, + FRAC_1_SQRT_2, + E, + LOG2_10, + LOG2_E, + LOG10_2, + LOG10_E, + LN_2, + LN_10 + ) + }; + ($($name:ident),*) => {{ + use $crate::ContextWithMutableVariables; + $crate::context_map! { + $( + stringify!($name) => core::f64::consts::$name, + )* + } + }}; +}