Skip to content

Commit 5557c33

Browse files
committed
---
yaml --- r: 95200 b: refs/heads/dist-snap c: 9de7ad2 h: refs/heads/master v: v3
1 parent 2c42789 commit 5557c33

File tree

4 files changed

+67
-63
lines changed

4 files changed

+67
-63
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 5a64e1a35a17c7aebd91e0d2fc9003f08fb5fd6d
9+
refs/heads/dist-snap: 9de7ad2d8c1729b7b11c6d234fc8ef8ce96809bb
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libextra/num/bigint.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ A `BigInt` is a combination of `BigUint` and `Sign`.
2020
#[allow(non_uppercase_statics)];
2121

2222
use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
23-
use std::int;
2423
use std::num;
2524
use std::num::{Zero, One, ToStrRadix, FromStrRadix, Orderable};
2625
use std::num::{ToPrimitive, FromPrimitive};
2726
use std::rand::Rng;
2827
use std::str;
2928
use std::uint;
29+
use std::{i64, u64};
3030
use std::vec;
3131

3232
/**
@@ -503,42 +503,42 @@ impl Integer for BigUint {
503503

504504
impl ToPrimitive for BigUint {
505505
#[inline]
506-
fn to_int(&self) -> Option<int> {
506+
fn to_i64(&self) -> Option<i64> {
507507
do self.to_uint().and_then |n| {
508-
// If top bit of uint is set, it's too large to convert to
508+
// If top bit of u64 is set, it's too large to convert to
509509
// int.
510510
if (n >> (2*BigDigit::bits - 1) != 0) {
511511
None
512512
} else {
513-
Some(n as int)
513+
Some(n as i64)
514514
}
515515
}
516516
}
517517

518518
#[inline]
519-
fn to_uint(&self) -> Option<uint> {
519+
fn to_u64(&self) -> Option<u64> {
520520
match self.data.len() {
521521
0 => Some(0),
522-
1 => Some(self.data[0] as uint),
523-
2 => Some(BigDigit::to_uint(self.data[1], self.data[0])),
522+
1 => Some(self.data[0] as u64),
523+
2 => Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64),
524524
_ => None
525525
}
526526
}
527527
}
528528

529529
impl FromPrimitive for BigUint {
530530
#[inline]
531-
fn from_int(n: int) -> Option<BigUint> {
531+
fn from_i64(n: i64) -> Option<BigUint> {
532532
if (n < 0) {
533533
Some(Zero::zero())
534534
} else {
535-
FromPrimitive::from_uint(n as uint)
535+
FromPrimitive::from_u64(n as u64)
536536
}
537537
}
538538

539539
#[inline]
540-
fn from_uint(n: uint) -> Option<BigUint> {
541-
let n = match BigDigit::from_uint(n) {
540+
fn from_u64(n: u64) -> Option<BigUint> {
541+
let n = match BigDigit::from_uint(n as uint) {
542542
(0, 0) => Zero::zero(),
543543
(0, n0) => BigUint::new(~[n0]),
544544
(n1, n0) => BigUint::new(~[n0, n1])
@@ -1083,29 +1083,29 @@ impl Integer for BigInt {
10831083

10841084
impl ToPrimitive for BigInt {
10851085
#[inline]
1086-
fn to_int(&self) -> Option<int> {
1086+
fn to_i64(&self) -> Option<i64> {
10871087
match self.sign {
1088-
Plus => self.data.to_int(),
1088+
Plus => self.data.to_i64(),
10891089
Zero => Some(0),
10901090
Minus => {
1091-
do self.data.to_uint().and_then |n| {
1092-
let m: uint = 1 << (2*BigDigit::bits-1);
1091+
do self.data.to_u64().and_then |n| {
1092+
let m: u64 = 1 << (2*BigDigit::bits-1);
10931093
if (n > m) {
10941094
None
10951095
} else if (n == m) {
1096-
Some(int::min_value)
1096+
Some(i64::min_value)
10971097
} else {
1098-
Some(-(n as int))
1098+
Some(-(n as i64))
10991099
}
11001100
}
11011101
}
11021102
}
11031103
}
11041104

11051105
#[inline]
1106-
fn to_uint(&self) -> Option<uint> {
1106+
fn to_u64(&self) -> Option<u64> {
11071107
match self.sign {
1108-
Plus => self.data.to_uint(),
1108+
Plus => self.data.to_u64(),
11091109
Zero => Some(0),
11101110
Minus => None
11111111
}
@@ -1114,13 +1114,13 @@ impl ToPrimitive for BigInt {
11141114

11151115
impl FromPrimitive for BigInt {
11161116
#[inline]
1117-
fn from_int(n: int) -> Option<BigInt> {
1117+
fn from_i64(n: i64) -> Option<BigInt> {
11181118
if n > 0 {
1119-
do FromPrimitive::from_uint(n as uint).and_then |n| {
1119+
do FromPrimitive::from_u64(n as u64).and_then |n| {
11201120
Some(BigInt::from_biguint(Plus, n))
11211121
}
11221122
} else if n < 0 {
1123-
do FromPrimitive::from_uint(uint::max_value - (n as uint) + 1).and_then |n| {
1123+
do FromPrimitive::from_u64(u64::max_value - (n as u64) + 1).and_then |n| {
11241124
Some(BigInt::from_biguint(Minus, n))
11251125
}
11261126
} else {
@@ -1129,11 +1129,11 @@ impl FromPrimitive for BigInt {
11291129
}
11301130

11311131
#[inline]
1132-
fn from_uint(n: uint) -> Option<BigInt> {
1132+
fn from_u64(n: u64) -> Option<BigInt> {
11331133
if n == 0 {
11341134
Some(Zero::zero())
11351135
} else {
1136-
do FromPrimitive::from_uint(n).and_then |n| {
1136+
do FromPrimitive::from_u64(n).and_then |n| {
11371137
Some(BigInt::from_biguint(Plus, n))
11381138
}
11391139
}

branches/dist-snap/src/libstd/num/num.rs

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -351,65 +351,69 @@ pub trait Float: Real
351351
/// A generic trait for converting a value to a number.
352352
pub trait ToPrimitive {
353353
/// Converts the value of `self` to an `int`.
354-
fn to_int(&self) -> Option<int>;
354+
#[inline]
355+
fn to_int(&self) -> Option<int> {
356+
// XXX: Check for range.
357+
self.to_i64().and_then(|x| Some(x as int))
358+
}
355359

356360
/// Converts the value of `self` to an `i8`.
357361
#[inline]
358362
fn to_i8(&self) -> Option<i8> {
359363
// XXX: Check for range.
360-
self.to_int().and_then(|x| Some(x as i8))
364+
self.to_i64().and_then(|x| Some(x as i8))
361365
}
362366

363367
/// Converts the value of `self` to an `i16`.
364368
#[inline]
365369
fn to_i16(&self) -> Option<i16> {
366370
// XXX: Check for range.
367-
self.to_int().and_then(|x| Some(x as i16))
371+
self.to_i64().and_then(|x| Some(x as i16))
368372
}
369373

370374
/// Converts the value of `self` to an `i32`.
371375
#[inline]
372376
fn to_i32(&self) -> Option<i32> {
373377
// XXX: Check for range.
374-
self.to_int().and_then(|x| Some(x as i32))
378+
self.to_i64().and_then(|x| Some(x as i32))
375379
}
376380

377381
/// Converts the value of `self` to an `i64`.
382+
fn to_i64(&self) -> Option<i64>;
383+
384+
/// Converts the value of `self` to an `uint`.
378385
#[inline]
379-
fn to_i64(&self) -> Option<i64> {
386+
fn to_uint(&self) -> Option<uint> {
380387
// XXX: Check for range.
381-
self.to_int().and_then(|x| Some(x as i64))
388+
self.to_u64().and_then(|x| Some(x as uint))
382389
}
383390

384-
/// Converts the value of `self` to an `uint`.
385-
fn to_uint(&self) -> Option<uint>;
386-
387391
/// Converts the value of `self` to an `u8`.
388392
#[inline]
389393
fn to_u8(&self) -> Option<u8> {
390394
// XXX: Check for range.
391-
self.to_uint().and_then(|x| Some(x as u8))
395+
self.to_u64().and_then(|x| Some(x as u8))
392396
}
393397

394398
/// Converts the value of `self` to an `u16`.
395399
#[inline]
396400
fn to_u16(&self) -> Option<u16> {
397401
// XXX: Check for range.
398-
self.to_uint().and_then(|x| Some(x as u16))
402+
self.to_u64().and_then(|x| Some(x as u16))
399403
}
400404

401405
/// Converts the value of `self` to an `u32`.
402406
#[inline]
403407
fn to_u32(&self) -> Option<u32> {
404408
// XXX: Check for range.
405-
self.to_uint().and_then(|x| Some(x as u32))
409+
self.to_u64().and_then(|x| Some(x as u32))
406410
}
407411

408412
/// Converts the value of `self` to an `u64`.
409413
#[inline]
410414
fn to_u64(&self) -> Option<u64> {
411415
// XXX: Check for range.
412-
self.to_uint().and_then(|x| Some(x as u64))
416+
self.to_u64().and_then(|x| Some(x as u64))
413417
}
414418

415419
/// Converts the value of `self` to an `f32`.
@@ -423,7 +427,7 @@ pub trait ToPrimitive {
423427
#[inline]
424428
fn to_f64(&self) -> Option<f64> {
425429
// XXX: Check for range.
426-
self.to_float().and_then(|x| Some(x as f64))
430+
self.to_i64().and_then(|x| Some(x as f64))
427431
}
428432
}
429433

@@ -467,80 +471,80 @@ impl_to_primitive!(float)
467471
pub trait FromPrimitive {
468472
/// Convert an `int` to return an optional value of this type. If the
469473
/// value cannot be represented by this value, the `None` is returned.
470-
fn from_int(n: int) -> Option<Self>;
474+
#[inline]
475+
fn from_int(n: int) -> Option<Self> {
476+
FromPrimitive::from_i64(n as i64)
477+
}
471478

472479
/// Convert an `i8` to return an optional value of this type. If the
473480
/// type cannot be represented by this value, the `None` is returned.
474481
#[inline]
475482
fn from_i8(n: i8) -> Option<Self> {
476-
FromPrimitive::from_int(n as int)
483+
FromPrimitive::from_i64(n as i64)
477484
}
478485

479486
/// Convert an `i16` to return an optional value of this type. If the
480487
/// type cannot be represented by this value, the `None` is returned.
481488
#[inline]
482489
fn from_i16(n: i16) -> Option<Self> {
483-
FromPrimitive::from_int(n as int)
490+
FromPrimitive::from_i64(n as i64)
484491
}
485492

486493
/// Convert an `i32` to return an optional value of this type. If the
487494
/// type cannot be represented by this value, the `None` is returned.
488495
#[inline]
489496
fn from_i32(n: i32) -> Option<Self> {
490-
FromPrimitive::from_int(n as int)
497+
FromPrimitive::from_i64(n as i64)
491498
}
492499

493500
/// Convert an `i64` to return an optional value of this type. If the
494501
/// type cannot be represented by this value, the `None` is returned.
495-
#[inline]
496-
fn from_i64(n: i64) -> Option<Self> {
497-
FromPrimitive::from_int(n as int)
498-
}
502+
fn from_i64(n: i64) -> Option<Self>;
499503

500504
/// Convert an `uint` to return an optional value of this type. If the
501505
/// type cannot be represented by this value, the `None` is returned.
502-
fn from_uint(n: uint) -> Option<Self>;
506+
#[inline]
507+
fn from_uint(n: uint) -> Option<Self> {
508+
FromPrimitive::from_u64(n as u64)
509+
}
503510

504511
/// Convert an `u8` to return an optional value of this type. If the
505512
/// type cannot be represented by this value, the `None` is returned.
506513
#[inline]
507514
fn from_u8(n: u8) -> Option<Self> {
508-
FromPrimitive::from_uint(n as uint)
515+
FromPrimitive::from_u64(n as u64)
509516
}
510517

511518
/// Convert an `u16` to return an optional value of this type. If the
512519
/// type cannot be represented by this value, the `None` is returned.
513520
#[inline]
514521
fn from_u16(n: u16) -> Option<Self> {
515-
FromPrimitive::from_uint(n as uint)
522+
FromPrimitive::from_u64(n as u64)
516523
}
517524

518525
/// Convert an `u32` to return an optional value of this type. If the
519526
/// type cannot be represented by this value, the `None` is returned.
520527
#[inline]
521528
fn from_u32(n: u32) -> Option<Self> {
522-
FromPrimitive::from_uint(n as uint)
529+
FromPrimitive::from_u64(n as u64)
523530
}
524531

525532
/// Convert an `u64` to return an optional value of this type. If the
526533
/// type cannot be represented by this value, the `None` is returned.
527-
#[inline]
528-
fn from_u64(n: u64) -> Option<Self> {
529-
FromPrimitive::from_uint(n as uint)
530-
}
534+
fn from_u64(n: u64) -> Option<Self>;
531535

532536
/// Convert a `f32` to return an optional value of this type. If the
533537
/// type cannot be represented by this value, the `None` is returned.
534538
#[inline]
535539
fn from_f32(n: f32) -> Option<Self> {
536-
FromPrimitive::from_float(n as float)
540+
FromPrimitive::from_f64(n as f64)
537541
}
538542

539543
/// Convert a `f64` to return an optional value of this type. If the
540544
/// type cannot be represented by this value, the `None` is returned.
541545
#[inline]
542546
fn from_f64(n: f64) -> Option<Self> {
543-
FromPrimitive::from_float(n as float)
547+
FromPrimitive::from_i64(n as i64)
544548
}
545549
}
546550

branches/dist-snap/src/libsyntax/ext/deriving/primitive.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ pub fn expand_deriving_from_primitive(cx: @ExtCtxt,
2525
generics: LifetimeBounds::empty(),
2626
methods: ~[
2727
MethodDef {
28-
name: "from_int",
28+
name: "from_i64",
2929
generics: LifetimeBounds::empty(),
3030
explicit_self: None,
3131
args: ~[
32-
Literal(Path::new(~["int"])),
32+
Literal(Path::new(~["i64"])),
3333
],
3434
ret_ty: Literal(Path::new_(~["std", "option", "Option"],
3535
None,
3636
~[~Self],
3737
true)),
3838
const_nonmatching: false,
39-
combine_substructure: |c, s, sub| cs_from("int", c, s, sub),
39+
combine_substructure: |c, s, sub| cs_from("i64", c, s, sub),
4040
},
4141
MethodDef {
42-
name: "from_uint",
42+
name: "from_u64",
4343
generics: LifetimeBounds::empty(),
4444
explicit_self: None,
4545
args: ~[
46-
Literal(Path::new(~["uint"])),
46+
Literal(Path::new(~["u64"])),
4747
],
4848
ret_ty: Literal(Path::new_(~["std", "option", "Option"],
4949
None,
5050
~[~Self],
5151
true)),
5252
const_nonmatching: false,
53-
combine_substructure: |c, s, sub| cs_from("uint", c, s, sub),
53+
combine_substructure: |c, s, sub| cs_from("u64", c, s, sub),
5454
},
5555
]
5656
};

0 commit comments

Comments
 (0)