Skip to content

Commit 02e04f3

Browse files
committed
---
yaml --- r: 63191 b: refs/heads/snap-stage3 c: df5b0c0 h: refs/heads/master i: 63189: d430793 63187: f85dcce 63183: 9749d7d v: v3
1 parent 842583f commit 02e04f3

File tree

9 files changed

+81
-122
lines changed

9 files changed

+81
-122
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 19c31b6b1afef7cad83275b2e73d27e5c44ed2a1
4+
refs/heads/snap-stage3: df5b0c040c744879705b4c37be3bb1cbe7282ab2
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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() {

branches/snap-stage3/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::*;

branches/snap-stage3/src/librustc/middle/resolve.rs

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,6 @@ pub enum DuplicateCheckingMode {
294294
OverwriteDuplicates
295295
}
296296

297-
// Returns the namespace associated with the given duplicate checking mode,
298-
// or fails for OverwriteDuplicates. This is used for error messages.
299-
pub fn namespace_for_duplicate_checking_mode(mode: DuplicateCheckingMode)
300-
-> Namespace {
301-
match mode {
302-
ForbidDuplicateModules | ForbidDuplicateTypes |
303-
ForbidDuplicateTypesAndValues => TypeNS,
304-
ForbidDuplicateValues => ValueNS,
305-
OverwriteDuplicates => fail!("OverwriteDuplicates has no namespace")
306-
}
307-
}
308-
309297
/// One local scope.
310298
pub struct Rib {
311299
bindings: @mut HashMap<ident,def_like>,
@@ -1007,37 +995,43 @@ impl Resolver {
1007995
// nothing.
1008996

1009997
let mut is_duplicate = false;
1010-
match duplicate_checking_mode {
998+
let ns = match duplicate_checking_mode {
1011999
ForbidDuplicateModules => {
1012-
is_duplicate =
1013-
child.get_module_if_available().is_some();
1000+
is_duplicate = child.get_module_if_available().is_some();
1001+
Some(TypeNS)
10141002
}
10151003
ForbidDuplicateTypes => {
10161004
match child.def_for_namespace(TypeNS) {
10171005
Some(def_mod(_)) | None => {}
10181006
Some(_) => is_duplicate = true
10191007
}
1008+
Some(TypeNS)
10201009
}
10211010
ForbidDuplicateValues => {
10221011
is_duplicate = child.defined_in_namespace(ValueNS);
1012+
Some(ValueNS)
10231013
}
10241014
ForbidDuplicateTypesAndValues => {
1015+
let mut n = None;
10251016
match child.def_for_namespace(TypeNS) {
10261017
Some(def_mod(_)) | None => {}
1027-
Some(_) => is_duplicate = true
1018+
Some(_) => {
1019+
n = Some(TypeNS);
1020+
is_duplicate = true;
1021+
}
10281022
};
10291023
if child.defined_in_namespace(ValueNS) {
10301024
is_duplicate = true;
1025+
n = Some(ValueNS);
10311026
}
1027+
n
10321028
}
1033-
OverwriteDuplicates => {}
1034-
}
1035-
if duplicate_checking_mode != OverwriteDuplicates &&
1036-
is_duplicate {
1029+
OverwriteDuplicates => None
1030+
};
1031+
if is_duplicate {
10371032
// Return an error here by looking up the namespace that
10381033
// had the duplicate.
1039-
let ns = namespace_for_duplicate_checking_mode(
1040-
duplicate_checking_mode);
1034+
let ns = ns.unwrap();
10411035
self.session.span_err(sp,
10421036
fmt!("duplicate definition of %s `%s`",
10431037
namespace_to_str(ns),
@@ -1195,22 +1189,22 @@ impl Resolver {
11951189

11961190
// These items live in both the type and value namespaces.
11971191
item_struct(struct_def, _) => {
1198-
let (name_bindings, new_parent) =
1199-
self.add_child(ident, parent, ForbidDuplicateTypes, sp);
1192+
// Adding to both Type and Value namespaces or just Type?
1193+
let (forbid, ctor_id) = match struct_def.ctor_id {
1194+
Some(ctor_id) => (ForbidDuplicateTypesAndValues, Some(ctor_id)),
1195+
None => (ForbidDuplicateTypes, None)
1196+
};
12001197

1201-
name_bindings.define_type(
1202-
privacy, def_ty(local_def(item.id)), sp);
1198+
let (name_bindings, new_parent) = self.add_child(ident, parent, forbid, sp);
12031199

1204-
// If this struct is tuple-like or enum-like, define a name
1205-
// in the value namespace.
1206-
match struct_def.ctor_id {
1207-
None => {}
1208-
Some(ctor_id) => {
1209-
name_bindings.define_value(
1210-
privacy,
1211-
def_struct(local_def(ctor_id)),
1212-
sp);
1213-
}
1200+
// Define a name in the type namespace.
1201+
name_bindings.define_type(privacy, def_ty(local_def(item.id)), sp);
1202+
1203+
// If this is a newtype or unit-like struct, define a name
1204+
// in the value namespace as well
1205+
do ctor_id.while_some |cid| {
1206+
name_bindings.define_value(privacy, def_struct(local_def(cid)), sp);
1207+
None
12141208
}
12151209

12161210
// Record the def ID of this struct.

branches/snap-stage3/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)]

branches/snap-stage3/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)]

0 commit comments

Comments
 (0)