From 30d787ae9b137f53b63e66b0e3fd25da006b8a8f Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Fri, 12 Apr 2024 14:55:13 +0200 Subject: [PATCH] add constants in std::f128::consts --- library/core/src/num/f128.rs | 111 ++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index 12e1cb78e6f..8fe81a9f528 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -15,7 +15,116 @@ /// Basic mathematical constants. #[unstable(feature = "f128", issue = "116909")] -pub mod consts {} +pub mod consts { + // FIXME: replace with mathematical constants from cmath. + + /// Archimedes' constant (π) + #[unstable(feature = "f128", issue = "116909")] + pub const PI: f128 = 3.14159265358979323846264338327950288419716939937510582097494_f128; + + /// The full circle constant (τ) + /// + /// Equal to 2π. + #[unstable(feature = "f128", issue = "116909")] + pub const TAU: f128 = 6.28318530717958647692528676655900576839433879875021164194989_f128; + + /// The golden ratio (φ) + #[unstable(feature = "f128", issue = "116909")] + // Also, #[unstable(feature = "more_float_constants", issue = "103883")] + pub const PHI: f128 = 1.61803398874989484820458683436563811772030917980576286213545_f128; + + /// The Euler-Mascheroni constant (γ) + #[unstable(feature = "f128", issue = "116909")] + // Also, #[unstable(feature = "more_float_constants", issue = "103883")] + pub const EGAMMA: f128 = 0.577215664901532860606512090082402431042159335939923598805767_f128; + + /// π/2 + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_PI_2: f128 = 1.57079632679489661923132169163975144209858469968755291048747_f128; + + /// π/3 + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_PI_3: f128 = 1.04719755119659774615421446109316762806572313312503527365831_f128; + + /// π/4 + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_PI_4: f128 = 0.785398163397448309615660845819875721049292349843776455243736_f128; + + /// π/6 + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_PI_6: f128 = 0.523598775598298873077107230546583814032861566562517636829157_f128; + + /// π/8 + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_PI_8: f128 = 0.392699081698724154807830422909937860524646174921888227621868_f128; + + /// 1/π + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_1_PI: f128 = 0.318309886183790671537767526745028724068919291480912897495335_f128; + + /// 1/sqrt(π) + #[unstable(feature = "f128", issue = "116909")] + // Also, #[unstable(feature = "more_float_constants", issue = "103883")] + pub const FRAC_1_SQRT_PI: f128 = + 0.564189583547756286948079451560772585844050629328998856844086_f128; + + /// 2/π + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_2_PI: f128 = 0.636619772367581343075535053490057448137838582961825794990669_f128; + + /// 2/sqrt(π) + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_2_SQRT_PI: f128 = + 1.12837916709551257389615890312154517168810125865799771368817_f128; + + /// sqrt(2) + #[unstable(feature = "f128", issue = "116909")] + pub const SQRT_2: f128 = 1.41421356237309504880168872420969807856967187537694807317668_f128; + + /// 1/sqrt(2) + #[unstable(feature = "f128", issue = "116909")] + pub const FRAC_1_SQRT_2: f128 = + 0.707106781186547524400844362104849039284835937688474036588340_f128; + + /// sqrt(3) + #[unstable(feature = "f128", issue = "116909")] + // Also, #[unstable(feature = "more_float_constants", issue = "103883")] + pub const SQRT_3: f128 = 1.73205080756887729352744634150587236694280525381038062805581_f128; + + /// 1/sqrt(3) + #[unstable(feature = "f128", issue = "116909")] + // Also, #[unstable(feature = "more_float_constants", issue = "103883")] + pub const FRAC_1_SQRT_3: f128 = + 0.577350269189625764509148780501957455647601751270126876018602_f128; + + /// Euler's number (e) + #[unstable(feature = "f128", issue = "116909")] + pub const E: f128 = 2.71828182845904523536028747135266249775724709369995957496697_f128; + + /// log2(10) + #[unstable(feature = "f128", issue = "116909")] + pub const LOG2_10: f128 = 3.32192809488736234787031942948939017586483139302458061205476_f128; + + /// log2(e) + #[unstable(feature = "f128", issue = "116909")] + pub const LOG2_E: f128 = 1.44269504088896340735992468100189213742664595415298593413545_f128; + + /// log10(2) + #[unstable(feature = "f128", issue = "116909")] + pub const LOG10_2: f128 = 0.301029995663981195213738894724493026768189881462108541310427_f128; + + /// log10(e) + #[unstable(feature = "f128", issue = "116909")] + pub const LOG10_E: f128 = 0.434294481903251827651128918916605082294397005803666566114454_f128; + + /// ln(2) + #[unstable(feature = "f128", issue = "116909")] + pub const LN_2: f128 = 0.693147180559945309417232121458176568075500134360255254120680_f128; + + /// ln(10) + #[unstable(feature = "f128", issue = "116909")] + pub const LN_10: f128 = 2.30258509299404568401799145468436420760110148862877297603333_f128; +} #[cfg(not(test))] impl f128 {