Skip to content

Commit 2e56f6d

Browse files
committed
---
yaml --- r: 65776 b: refs/heads/master c: 1ac90bb h: refs/heads/master v: v3
1 parent 5f379ac commit 2e56f6d

File tree

8 files changed

+42
-87
lines changed

8 files changed

+42
-87
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 075da9c3e9f326589056abd6edf1f196f6b2e244
2+
refs/heads/master: 1ac90bb74be2eec589c6af3f24885fc01fae5494
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/doc/tutorial-tasks.md

Lines changed: 2 additions & 2 deletions
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() {

trunk/src/libextra/num/complex.rs

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub type Complex = Cmplx<float>;
3535
pub type Complex32 = Cmplx<f32>;
3636
pub type Complex64 = Cmplx<f64>;
3737

38-
impl<T: Clone + Num> Cmplx<T> {
38+
impl<T: Copy + Num> Cmplx<T> {
3939
/// Create a new Cmplx
4040
#[inline]
4141
pub fn new(re: T, im: T) -> Cmplx<T> {
@@ -55,7 +55,7 @@ impl<T: Clone + Num> Cmplx<T> {
5555
/// Returns the complex conjugate. i.e. `re - i im`
5656
#[inline]
5757
pub fn conj(&self) -> Cmplx<T> {
58-
Cmplx::new(self.re.clone(), -self.im)
58+
Cmplx::new(self.re, -self.im)
5959
}
6060

6161

@@ -80,91 +80,62 @@ impl<T: Clone + Num> Cmplx<T> {
8080
}
8181
}
8282

83-
#[cfg(not(stage0))] // Fixed by #4228
84-
impl<T: Clone + Algebraic + Num> Cmplx<T> {
85-
/// Calculate |self|
86-
#[inline(always)]
87-
pub fn norm(&self) -> T {
88-
self.re.hypot(&self.im)
89-
}
90-
}
91-
92-
#[cfg(not(stage0))] // Fixed by #4228
93-
impl<T: Clone + Trigonometric + Algebraic + Num> Cmplx<T> {
94-
/// Calculate the principal Arg of self.
95-
#[inline(always)]
96-
pub fn arg(&self) -> T {
97-
self.im.atan2(&self.re)
98-
}
99-
/// Convert to polar form (r, theta), such that `self = r * exp(i
100-
/// * theta)`
101-
#[inline]
102-
pub fn to_polar(&self) -> (T, T) {
103-
(self.norm(), self.arg())
104-
}
105-
/// Convert a polar representation into a complex number.
106-
#[inline]
107-
pub fn from_polar(r: &T, theta: &T) -> Cmplx<T> {
108-
Cmplx::new(r * theta.cos(), r * theta.sin())
109-
}
110-
}
111-
11283
/* arithmetic */
11384
// (a + i b) + (c + i d) == (a + c) + i (b + d)
114-
impl<T: Clone + Num> Add<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
85+
impl<T: Copy + Num> Add<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
11586
#[inline]
11687
fn add(&self, other: &Cmplx<T>) -> Cmplx<T> {
11788
Cmplx::new(self.re + other.re, self.im + other.im)
11889
}
11990
}
12091
// (a + i b) - (c + i d) == (a - c) + i (b - d)
121-
impl<T: Clone + Num> Sub<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
92+
impl<T: Copy + Num> Sub<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
12293
#[inline]
12394
fn sub(&self, other: &Cmplx<T>) -> Cmplx<T> {
12495
Cmplx::new(self.re - other.re, self.im - other.im)
12596
}
12697
}
12798
// (a + i b) * (c + i d) == (a*c - b*d) + i (a*d + b*c)
128-
impl<T: Clone + Num> Mul<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
99+
impl<T: Copy + Num> Mul<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
129100
#[inline]
130101
fn mul(&self, other: &Cmplx<T>) -> Cmplx<T> {
131102
Cmplx::new(self.re*other.re - self.im*other.im,
132-
self.re*other.im + self.im*other.re)
103+
self.re*other.im + self.im*other.re)
133104
}
134105
}
135106

136107
// (a + i b) / (c + i d) == [(a + i b) * (c - i d)] / (c*c + d*d)
137108
// == [(a*c + b*d) / (c*c + d*d)] + i [(b*c - a*d) / (c*c + d*d)]
138-
impl<T: Clone + Num> Div<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
109+
impl<T: Copy + Num> Div<Cmplx<T>, Cmplx<T>> for Cmplx<T> {
139110
#[inline]
140111
fn div(&self, other: &Cmplx<T>) -> Cmplx<T> {
141112
let norm_sqr = other.norm_sqr();
142113
Cmplx::new((self.re*other.re + self.im*other.im) / norm_sqr,
143-
(self.im*other.re - self.re*other.im) / norm_sqr)
114+
(self.im*other.re - self.re*other.im) / norm_sqr)
144115
}
145116
}
146117

147-
impl<T: Clone + Num> Neg<Cmplx<T>> for Cmplx<T> {
118+
impl<T: Copy + Num> Neg<Cmplx<T>> for Cmplx<T> {
148119
#[inline]
149120
fn neg(&self) -> Cmplx<T> {
150121
Cmplx::new(-self.re, -self.im)
151122
}
152123
}
153124

154125
/* constants */
155-
impl<T: Clone + Num> Zero for Cmplx<T> {
126+
impl<T: Copy + Num> Zero for Cmplx<T> {
156127
#[inline]
157128
fn zero() -> Cmplx<T> {
158129
Cmplx::new(Zero::zero(), Zero::zero())
159130
}
160131

161132
#[inline]
162133
fn is_zero(&self) -> bool {
163-
self.re.is_zero() && self.im.is_zero()
134+
*self == Zero::zero()
164135
}
165136
}
166137

167-
impl<T: Clone + Num> One for Cmplx<T> {
138+
impl<T: Copy + Num> One for Cmplx<T> {
168139
#[inline]
169140
fn one() -> Cmplx<T> {
170141
Cmplx::new(One::one(), Zero::zero())
@@ -195,7 +166,7 @@ impl<T: ToStrRadix + Num + Ord> ToStrRadix for Cmplx<T> {
195166
#[cfg(test)]
196167
mod test {
197168
use super::*;
198-
use core::num::{Zero,One,Real};
169+
use core::num::{Zero,One};
199170

200171
pub static _0_0i : Complex = Cmplx { re: 0f, im: 0f };
201172
pub static _1_0i : Complex = Cmplx { re: 1f, im: 0f };
@@ -222,10 +193,9 @@ mod test {
222193
}
223194

224195
#[test]
225-
fn test_norm() {
196+
fn test_norm_sqr() {
226197
fn test(c: Complex, ns: float) {
227198
assert_eq!(c.norm_sqr(), ns);
228-
assert_eq!(c.norm(), ns.sqrt())
229199
}
230200
test(_0_0i, 0f);
231201
test(_1_0i, 1f);
@@ -265,25 +235,6 @@ mod test {
265235
_0_0i.inv();
266236
}
267237

268-
#[test]
269-
fn test_arg() {
270-
fn test(c: Complex, arg: float) {
271-
assert!(c.arg().approx_eq(&arg))
272-
}
273-
test(_1_0i, 0f);
274-
test(_1_1i, 0.25f * Real::pi());
275-
test(_neg1_1i, 0.75f * Real::pi());
276-
test(_05_05i, 0.25f * Real::pi());
277-
}
278-
279-
#[test]
280-
fn test_polar_conv() {
281-
fn test(c: Complex) {
282-
let (r, theta) = c.to_polar();
283-
assert!((c - Cmplx::from_polar(&r, &theta)).norm() < 1e-6);
284-
}
285-
for all_consts.each |&c| { test(c); }
286-
}
287238

288239
mod arith {
289240
use super::*;

trunk/src/libstd/num/f32.rs

Lines changed: 4 additions & 4 deletions
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)]

trunk/src/libstd/num/f64.rs

Lines changed: 4 additions & 4 deletions
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)]

trunk/src/libstd/num/float.rs

Lines changed: 8 additions & 8 deletions
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

trunk/src/libstd/num/num.rs

Lines changed: 4 additions & 4 deletions
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
}

trunk/src/libsyntax/parse/lexer.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,11 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
772772
'/' => { return binop(rdr, token::SLASH); }
773773
'^' => { return binop(rdr, token::CARET); }
774774
'%' => { return binop(rdr, token::PERCENT); }
775-
c => { rdr.fatal(fmt!("unknown start of token: %d", c as int)); }
775+
c => {
776+
// So the error span points to the unrecognized character
777+
rdr.peek_span = codemap::mk_sp(rdr.last_pos, rdr.pos);
778+
rdr.fatal(fmt!("unknown start of token: %d", c as int));
779+
}
776780
}
777781
}
778782

0 commit comments

Comments
 (0)