Skip to content

Commit 8badea4

Browse files
committed
auto merge of #6549 : bjz/rust/numeric-traits, r=thestinger
As discussed on issue #4819. This is a naive implementation, trusting LLVM to do the relevant optimizations. In the future this could be implemented more efficiently, but it's a start.
2 parents c69f8ea + 5696081 commit 8badea4

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/libcore/num/f32.rs

+6
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ impl Trigonometric for f32 {
414414

415415
#[inline(always)]
416416
fn atan2(&self, other: f32) -> f32 { atan2(*self, other) }
417+
418+
/// Simultaneously computes the sine and cosine of the number
419+
#[inline(always)]
420+
fn sin_cos(&self) -> (f32, f32) {
421+
(self.sin(), self.cos())
422+
}
417423
}
418424

419425
impl Exponential for f32 {

src/libcore/num/f64.rs

+6
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ impl Trigonometric for f64 {
426426

427427
#[inline(always)]
428428
fn atan2(&self, other: f64) -> f64 { atan2(*self, other) }
429+
430+
/// Simultaneously computes the sine and cosine of the number
431+
#[inline(always)]
432+
fn sin_cos(&self) -> (f64, f64) {
433+
(self.sin(), self.cos())
434+
}
429435
}
430436

431437
impl Exponential for f64 {

src/libcore/num/float.rs

+8
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,14 @@ impl Trigonometric for float {
530530
fn atan2(&self, other: float) -> float {
531531
(*self as f64).atan2(other as f64) as float
532532
}
533+
534+
/// Simultaneously computes the sine and cosine of the number
535+
#[inline(always)]
536+
fn sin_cos(&self) -> (float, float) {
537+
match (*self as f64).sin_cos() {
538+
(s, c) => (s as float, c as float)
539+
}
540+
}
533541
}
534542

535543
impl Exponential for float {

src/libcore/num/num.rs

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub trait Trigonometric {
118118
fn acos(&self) -> Self;
119119
fn atan(&self) -> Self;
120120
fn atan2(&self, other: Self) -> Self;
121+
fn sin_cos(&self) -> (Self, Self);
121122
}
122123

123124
pub trait Exponential {

0 commit comments

Comments
 (0)