about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>2013-05-17 12:30:02 +1000
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>2013-05-17 12:30:02 +1000
commit56960817814975eb992a6770deba3b110c23ae90 (patch)
tree1d4063782eb651e8b54fe1c92b7e6a75917b3dc2
parentcf0f760560385d59427e2b974f24a328345d829b (diff)
downloadrust-56960817814975eb992a6770deba3b110c23ae90.tar.gz
rust-56960817814975eb992a6770deba3b110c23ae90.zip
Implement sin_cos method for float, f64 and f32
-rw-r--r--src/libcore/num/f32.rs6
-rw-r--r--src/libcore/num/f64.rs6
-rw-r--r--src/libcore/num/float.rs8
-rw-r--r--src/libcore/num/num.rs1
4 files changed, 21 insertions, 0 deletions
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs
index af30e87bb0c..4a3ec3528f2 100644
--- a/src/libcore/num/f32.rs
+++ b/src/libcore/num/f32.rs
@@ -414,6 +414,12 @@ impl Trigonometric for f32 {
 
     #[inline(always)]
     fn atan2(&self, other: f32) -> f32 { atan2(*self, other) }
+
+    /// Simultaneously computes the sine and cosine of the number
+    #[inline(always)]
+    fn sin_cos(&self) -> (f32, f32) {
+        (self.sin(), self.cos())
+    }
 }
 
 impl Exponential for f32 {
diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs
index 240d84b8403..e370f43a003 100644
--- a/src/libcore/num/f64.rs
+++ b/src/libcore/num/f64.rs
@@ -426,6 +426,12 @@ impl Trigonometric for f64 {
 
     #[inline(always)]
     fn atan2(&self, other: f64) -> f64 { atan2(*self, other) }
+
+    /// Simultaneously computes the sine and cosine of the number
+    #[inline(always)]
+    fn sin_cos(&self) -> (f64, f64) {
+        (self.sin(), self.cos())
+    }
 }
 
 impl Exponential for f64 {
diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs
index 8b3c7b1e79e..681aafaab88 100644
--- a/src/libcore/num/float.rs
+++ b/src/libcore/num/float.rs
@@ -530,6 +530,14 @@ impl Trigonometric for float {
     fn atan2(&self, other: float) -> float {
         (*self as f64).atan2(other as f64) as float
     }
+
+    /// Simultaneously computes the sine and cosine of the number
+    #[inline(always)]
+    fn sin_cos(&self) -> (float, float) {
+        match (*self as f64).sin_cos() {
+            (s, c) => (s as float, c as float)
+        }
+    }
 }
 
 impl Exponential for float {
diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs
index a15a8f1a215..c661e7ea1f8 100644
--- a/src/libcore/num/num.rs
+++ b/src/libcore/num/num.rs
@@ -118,6 +118,7 @@ pub trait Trigonometric {
     fn acos(&self) -> Self;
     fn atan(&self) -> Self;
     fn atan2(&self, other: Self) -> Self;
+    fn sin_cos(&self) -> (Self, Self);
 }
 
 pub trait Exponential {