Skip to content

Commit

Permalink
Implement sin_cos method for float, f64 and f32
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed May 17, 2013
1 parent cf0f760 commit 5696081
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/num/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/libcore/num/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5696081

Please sign in to comment.