Skip to content

Commit 7e6a594

Browse files
committed
std: convert pow, hypot, atan2, log to take arguments by reference.
1 parent 37733c7 commit 7e6a594

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

doc/tutorial-tasks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ be distributed on the available cores.
318318
fn partial_sum(start: uint) -> f64 {
319319
let mut local_sum = 0f64;
320320
for uint::range(start*100000, (start+1)*100000) |num| {
321-
local_sum += (num as f64 + 1.0).pow(-2.0);
321+
local_sum += (num as f64 + 1.0).pow(&-2.0);
322322
}
323323
local_sum
324324
}
@@ -355,7 +355,7 @@ a single large vector of floats. Each task needs the full vector to perform its
355355
use extra::arc::ARC;
356356
357357
fn pnorm(nums: &~[float], p: uint) -> float {
358-
nums.iter().fold(0.0, |a,b| a+(*b).pow(p as float) ).pow(1f / (p as float))
358+
nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as float)) ).pow(&(1f / (p as float)))
359359
}
360360
361361
fn main() {

src/libstd/num/f32.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl Fractional for f32 {
391391

392392
impl Algebraic for f32 {
393393
#[inline(always)]
394-
fn pow(&self, n: f32) -> f32 { pow(*self, n) }
394+
fn pow(&self, n: &f32) -> f32 { pow(*self, *n) }
395395

396396
#[inline(always)]
397397
fn sqrt(&self) -> f32 { sqrt(*self) }
@@ -403,7 +403,7 @@ impl Algebraic for f32 {
403403
fn cbrt(&self) -> f32 { cbrt(*self) }
404404

405405
#[inline(always)]
406-
fn hypot(&self, other: f32) -> f32 { hypot(*self, other) }
406+
fn hypot(&self, other: &f32) -> f32 { hypot(*self, *other) }
407407
}
408408

409409
impl Trigonometric for f32 {
@@ -426,7 +426,7 @@ impl Trigonometric for f32 {
426426
fn atan(&self) -> f32 { atan(*self) }
427427

428428
#[inline(always)]
429-
fn atan2(&self, other: f32) -> f32 { atan2(*self, other) }
429+
fn atan2(&self, other: &f32) -> f32 { atan2(*self, *other) }
430430

431431
/// Simultaneously computes the sine and cosine of the number
432432
#[inline(always)]
@@ -450,7 +450,7 @@ impl Exponential for f32 {
450450

451451
/// Returns the logarithm of the number with respect to an arbitrary base
452452
#[inline(always)]
453-
fn log(&self, base: f32) -> f32 { self.ln() / base.ln() }
453+
fn log(&self, base: &f32) -> f32 { self.ln() / base.ln() }
454454

455455
/// Returns the base 2 logarithm of the number
456456
#[inline(always)]

src/libstd/num/f64.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl Fractional for f64 {
403403

404404
impl Algebraic for f64 {
405405
#[inline(always)]
406-
fn pow(&self, n: f64) -> f64 { pow(*self, n) }
406+
fn pow(&self, n: &f64) -> f64 { pow(*self, *n) }
407407

408408
#[inline(always)]
409409
fn sqrt(&self) -> f64 { sqrt(*self) }
@@ -415,7 +415,7 @@ impl Algebraic for f64 {
415415
fn cbrt(&self) -> f64 { cbrt(*self) }
416416

417417
#[inline(always)]
418-
fn hypot(&self, other: f64) -> f64 { hypot(*self, other) }
418+
fn hypot(&self, other: &f64) -> f64 { hypot(*self, *other) }
419419
}
420420

421421
impl Trigonometric for f64 {
@@ -438,7 +438,7 @@ impl Trigonometric for f64 {
438438
fn atan(&self) -> f64 { atan(*self) }
439439

440440
#[inline(always)]
441-
fn atan2(&self, other: f64) -> f64 { atan2(*self, other) }
441+
fn atan2(&self, other: &f64) -> f64 { atan2(*self, *other) }
442442

443443
/// Simultaneously computes the sine and cosine of the number
444444
#[inline(always)]
@@ -462,7 +462,7 @@ impl Exponential for f64 {
462462

463463
/// Returns the logarithm of the number with respect to an arbitrary base
464464
#[inline(always)]
465-
fn log(&self, base: f64) -> f64 { self.ln() / base.ln() }
465+
fn log(&self, base: &f64) -> f64 { self.ln() / base.ln() }
466466

467467
/// Returns the base 2 logarithm of the number
468468
#[inline(always)]

src/libstd/num/float.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ impl Fractional for float {
475475

476476
impl Algebraic for float {
477477
#[inline(always)]
478-
fn pow(&self, n: float) -> float {
479-
(*self as f64).pow(n as f64) as float
478+
fn pow(&self, n: &float) -> float {
479+
(*self as f64).pow(&(*n as f64)) as float
480480
}
481481

482482
#[inline(always)]
@@ -495,8 +495,8 @@ impl Algebraic for float {
495495
}
496496

497497
#[inline(always)]
498-
fn hypot(&self, other: float) -> float {
499-
(*self as f64).hypot(other as f64) as float
498+
fn hypot(&self, other: &float) -> float {
499+
(*self as f64).hypot(&(*other as f64)) as float
500500
}
501501
}
502502

@@ -532,8 +532,8 @@ impl Trigonometric for float {
532532
}
533533

534534
#[inline(always)]
535-
fn atan2(&self, other: float) -> float {
536-
(*self as f64).atan2(other as f64) as float
535+
fn atan2(&self, other: &float) -> float {
536+
(*self as f64).atan2(&(*other as f64)) as float
537537
}
538538

539539
/// Simultaneously computes the sine and cosine of the number
@@ -566,8 +566,8 @@ impl Exponential for float {
566566

567567
/// Returns the logarithm of the number with respect to an arbitrary base
568568
#[inline(always)]
569-
fn log(&self, base: float) -> float {
570-
(*self as f64).log(base as f64) as float
569+
fn log(&self, base: &float) -> float {
570+
(*self as f64).log(&(*base as f64)) as float
571571
}
572572

573573
/// Returns the base 2 logarithm of the number

src/libstd/num/num.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ pub trait Fractional: Num
106106
}
107107

108108
pub trait Algebraic {
109-
fn pow(&self, n: Self) -> Self;
109+
fn pow(&self, n: &Self) -> Self;
110110
fn sqrt(&self) -> Self;
111111
fn rsqrt(&self) -> Self;
112112
fn cbrt(&self) -> Self;
113-
fn hypot(&self, other: Self) -> Self;
113+
fn hypot(&self, other: &Self) -> Self;
114114
}
115115

116116
pub trait Trigonometric {
@@ -120,15 +120,15 @@ pub trait Trigonometric {
120120
fn asin(&self) -> Self;
121121
fn acos(&self) -> Self;
122122
fn atan(&self) -> Self;
123-
fn atan2(&self, other: Self) -> Self;
123+
fn atan2(&self, other: &Self) -> Self;
124124
fn sin_cos(&self) -> (Self, Self);
125125
}
126126

127127
pub trait Exponential {
128128
fn exp(&self) -> Self;
129129
fn exp2(&self) -> Self;
130130
fn ln(&self) -> Self;
131-
fn log(&self, base: Self) -> Self;
131+
fn log(&self, base: &Self) -> Self;
132132
fn log2(&self) -> Self;
133133
fn log10(&self) -> Self;
134134
}

0 commit comments

Comments
 (0)