]> git.lizzy.rs Git - rust.git/commitdiff
Implement sin_cos method for float, f64 and f32
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>
Fri, 17 May 2013 02:30:02 +0000 (12:30 +1000)
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>
Fri, 17 May 2013 02:30:02 +0000 (12:30 +1000)
src/libcore/num/f32.rs
src/libcore/num/f64.rs
src/libcore/num/float.rs
src/libcore/num/num.rs

index af30e87bb0c659a638af22e40cd90b5367dde271..4a3ec3528f28b1231dd127e01d6e4d15f323ca83 100644 (file)
@@ -414,6 +414,12 @@ fn atan(&self) -> f32 { atan(*self) }
 
     #[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 {
index 240d84b84032a17993d8794ab5e13301490dec2f..e370f43a0037e0800c30abc857436752fedbb338 100644 (file)
@@ -426,6 +426,12 @@ fn atan(&self) -> f64 { atan(*self) }
 
     #[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 {
index 8b3c7b1e79ef88bfbc5892bc01a91b4643009479..681aafaab8884964b189045f56abfe8480885366 100644 (file)
@@ -530,6 +530,14 @@ fn atan(&self) -> 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 {
index a15a8f1a2153eb3b924f49d84f6b8bebf6d335e9..c661e7ea1f8235da82f7d15950c86891665739ab 100644 (file)
@@ -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 {