From 500078e147e1e5f5cf9bd57459ebbdda652d97ed Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 29 Apr 2013 23:38:58 +1000 Subject: [PATCH] Revert "Merge Exponential and Hyperbolic traits" After discussions on IRC and #4819, we have decided to revert this change. This is due to the traits expressing different ideas and because hyperbolic functions are not trivially implementable from exponential functions for floating-point types. --- src/libcore/core.rc | 2 +- src/libcore/num/f32.rs | 2 ++ src/libcore/num/f64.rs | 2 ++ src/libcore/num/float.rs | 2 ++ src/libcore/num/num.rs | 6 +++--- src/libcore/prelude.rs | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 979a02d9f9ca1..bf92a30f7ce20 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -105,7 +105,7 @@ pub use iter::{ExtendedMutableIter}; pub use num::{Num, NumCast}; pub use num::{Orderable, Signed, Unsigned, Round}; -pub use num::{Algebraic, Trigonometric, Exponential}; +pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic}; pub use num::{Integer, Fractional, Real, RealExt}; pub use num::{Bitwise, BitCount, Bounded}; pub use num::{Primitive, Int, Float}; diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 8c34219ae2172..e687f482fa98c 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -425,7 +425,9 @@ impl Exponential for f32 { #[inline(always)] fn log10(&self) -> f32 { log10(*self) } +} +impl Hyperbolic for f32 { #[inline(always)] fn sinh(&self) -> f32 { sinh(*self) } diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 19951ad7cffb9..d00e6ae2c0d79 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -437,7 +437,9 @@ impl Exponential for f64 { #[inline(always)] fn log10(&self) -> f64 { log10(*self) } +} +impl Hyperbolic for f64 { #[inline(always)] fn sinh(&self) -> f64 { sinh(*self) } diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index c64f36f065f50..3aa8848cdbed2 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -547,7 +547,9 @@ impl Exponential for float { fn log10(&self) -> float { (*self as f64).log10() as float } +} +impl Hyperbolic for float { #[inline(always)] fn sinh(&self) -> float { (*self as f64).sinh() as float diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs index 30a1213f7ff88..3e43ebfef1222 100644 --- a/src/libcore/num/num.rs +++ b/src/libcore/num/num.rs @@ -131,9 +131,9 @@ pub trait Exponential { fn log(&self) -> Self; fn log2(&self) -> Self; fn log10(&self) -> Self; +} - // The Hyperbolic Functions are trivially implemented in terms of `exp`, so it's simpler - // to group them within this trait. In the future these would have default implementations. +pub trait Hyperbolic: Exponential { fn sinh(&self) -> Self; fn cosh(&self) -> Self; fn tanh(&self) -> Self; @@ -146,7 +146,7 @@ pub trait Real: Signed + Fractional + Algebraic + Trigonometric - + Exponential { + + Hyperbolic { // Common Constants // FIXME (#5527): These should be associated constants fn pi() -> Self; diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 1b20efe0cca3d..5fef01e65de86 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -39,7 +39,7 @@ pub use iter::{CopyableIter, CopyableOrderedIter, CopyableNonstrictIter}; pub use iter::{Times, ExtendedMutableIter}; pub use num::{Num, NumCast}; pub use num::{Orderable, Signed, Unsigned, Round}; -pub use num::{Algebraic, Trigonometric, Exponential}; +pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic}; pub use num::{Integer, Fractional, Real, RealExt}; pub use num::{Bitwise, BitCount, Bounded}; pub use num::{Primitive, Int, Float};