mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 03:33:59 +00:00
Remove redundant 'extension' mods from numeric mods
This commit is contained in:
parent
43a48ca5bb
commit
7e6cbf7431
@ -12,19 +12,19 @@ import option_iter::extensions;
|
||||
import ptr::extensions;
|
||||
import rand::extensions;
|
||||
import result::extensions;
|
||||
import int::extensions::*;
|
||||
import i8::extensions::*;
|
||||
import i16::extensions::*;
|
||||
import i32::extensions::*;
|
||||
import i64::extensions::*;
|
||||
import uint::extensions::*;
|
||||
import u8::extensions::*;
|
||||
import u16::extensions::*;
|
||||
import u32::extensions::*;
|
||||
import u64::extensions::*;
|
||||
import float::extensions::*;
|
||||
import f32::extensions::*;
|
||||
import f64::extensions::*;
|
||||
import int::num;
|
||||
import i8::num;
|
||||
import i16::num;
|
||||
import i32::num;
|
||||
import i64::num;
|
||||
import uint::num;
|
||||
import u8::num;
|
||||
import u16::num;
|
||||
import u32::num;
|
||||
import u64::num;
|
||||
import float::num;
|
||||
import f32::num;
|
||||
import f64::num;
|
||||
|
||||
export path, option, some, none, unreachable;
|
||||
export extensions;
|
||||
|
@ -4,9 +4,8 @@
|
||||
|
||||
import cmath::c_float::*;
|
||||
import cmath::c_float_targ_consts::*;
|
||||
import num::num;
|
||||
|
||||
export add, sub, mul, div, rem, lt, le, gt, eq, eq, ne;
|
||||
export add, sub, mul, div, rem, lt, le, gt, eq, ne;
|
||||
export is_positive, is_negative, is_nonpositive, is_nonnegative;
|
||||
export is_zero, is_infinite, is_finite;
|
||||
export NaN, is_NaN, infinity, neg_infinity;
|
||||
@ -18,7 +17,8 @@ export mul_add, fmax, fmin, nextafter, frexp, hypot, ldexp;
|
||||
export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
|
||||
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
|
||||
export signbit;
|
||||
export extensions;
|
||||
|
||||
export num;
|
||||
|
||||
// These are not defined inside consts:: for consistency with
|
||||
// the integer types
|
||||
@ -173,18 +173,16 @@ pure fn log2(n: f32) -> f32 {
|
||||
ret ln(n) / consts::ln_2;
|
||||
}
|
||||
|
||||
mod extensions {
|
||||
impl num of num for f32 {
|
||||
fn add(&&other: f32) -> f32 { ret self + other; }
|
||||
fn sub(&&other: f32) -> f32 { ret self - other; }
|
||||
fn mul(&&other: f32) -> f32 { ret self * other; }
|
||||
fn div(&&other: f32) -> f32 { ret self / other; }
|
||||
fn modulo(&&other: f32) -> f32 { ret self % other; }
|
||||
fn neg() -> f32 { ret -self; }
|
||||
impl num of num::num for f32 {
|
||||
fn add(&&other: f32) -> f32 { ret self + other; }
|
||||
fn sub(&&other: f32) -> f32 { ret self - other; }
|
||||
fn mul(&&other: f32) -> f32 { ret self * other; }
|
||||
fn div(&&other: f32) -> f32 { ret self / other; }
|
||||
fn modulo(&&other: f32) -> f32 { ret self % other; }
|
||||
fn neg() -> f32 { ret -self; }
|
||||
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> f32 { ret n as f32; }
|
||||
}
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> f32 { ret n as f32; }
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -4,12 +4,11 @@
|
||||
|
||||
import cmath::c_double::*;
|
||||
import cmath::c_double_targ_consts::*;
|
||||
import num::num;
|
||||
|
||||
// Even though this module exports everything defined in it,
|
||||
// because it contains re-exports, we also have to explicitly
|
||||
// export locally defined things. That's a bit annoying.
|
||||
export add, sub, mul, div, rem, lt, le, gt, eq, eq, ne;
|
||||
export add, sub, mul, div, rem, lt, le, gt, eq, ne;
|
||||
export is_positive, is_negative, is_nonpositive, is_nonnegative;
|
||||
export is_zero, is_infinite, is_finite;
|
||||
export NaN, is_NaN, infinity, neg_infinity;
|
||||
@ -22,7 +21,10 @@ export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
|
||||
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
|
||||
export signbit;
|
||||
export epsilon;
|
||||
export extensions;
|
||||
|
||||
export j0, j1, jn, y0, y1, yn;
|
||||
|
||||
export num;
|
||||
|
||||
// These are not defined inside consts:: for consistency with
|
||||
// the integer types
|
||||
@ -196,18 +198,16 @@ pure fn log2(n: f64) -> f64 {
|
||||
ret ln(n) / consts::ln_2;
|
||||
}
|
||||
|
||||
mod extensions {
|
||||
impl num of num for f64 {
|
||||
fn add(&&other: f64) -> f64 { ret self + other; }
|
||||
fn sub(&&other: f64) -> f64 { ret self - other; }
|
||||
fn mul(&&other: f64) -> f64 { ret self * other; }
|
||||
fn div(&&other: f64) -> f64 { ret self / other; }
|
||||
fn modulo(&&other: f64) -> f64 { ret self % other; }
|
||||
fn neg() -> f64 { ret -self; }
|
||||
impl num of num::num for f64 {
|
||||
fn add(&&other: f64) -> f64 { ret self + other; }
|
||||
fn sub(&&other: f64) -> f64 { ret self - other; }
|
||||
fn mul(&&other: f64) -> f64 { ret self * other; }
|
||||
fn div(&&other: f64) -> f64 { ret self / other; }
|
||||
fn modulo(&&other: f64) -> f64 { ret self % other; }
|
||||
fn neg() -> f64 { ret -self; }
|
||||
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> f64 { ret n as f64; }
|
||||
}
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> f64 { ret n as f64; }
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -4,7 +4,7 @@
|
||||
// because it contains re-exports, we also have to explicitly
|
||||
// export locally defined things. That's a bit annoying.
|
||||
export to_str_common, to_str_exact, to_str, from_str;
|
||||
export add, sub, mul, div, rem, lt, le, gt, eq, eq, ne;
|
||||
export add, sub, mul, div, rem, lt, le, gt, eq, ne;
|
||||
export is_positive, is_negative, is_nonpositive, is_nonnegative;
|
||||
export is_zero, is_infinite, is_finite;
|
||||
export NaN, is_NaN, infinity, neg_infinity;
|
||||
@ -17,7 +17,8 @@ export lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix;
|
||||
export modf, pow, round, sin, sinh, sqrt, tan, tanh, tgamma, trunc;
|
||||
export signbit;
|
||||
export pow_with_uint;
|
||||
export extensions;
|
||||
|
||||
export num;
|
||||
|
||||
// export when m_float == c_double
|
||||
|
||||
@ -26,8 +27,16 @@ export j0, j1, jn, y0, y1, yn;
|
||||
// PORT this must match in width according to architecture
|
||||
|
||||
import m_float = f64;
|
||||
import f64::*;
|
||||
import num::num;
|
||||
|
||||
import f64::{add, sub, mul, div, rem, lt, le, gt, eq, ne};
|
||||
import f64::logarithm;
|
||||
import f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor};
|
||||
import f64::{erf, erfc, exp, expm1, exp2, abs_sub};
|
||||
import f64::{mul_add, fmax, fmin, nextafter, frexp, hypot, ldexp};
|
||||
import f64::{lgamma, ln, log_radix, ln1p, log10, log2, ilog_radix};
|
||||
import f64::{modf, pow, round, sinh, tanh, tgamma, trunc};
|
||||
import f64::signbit;
|
||||
import f64::{j0, j1, jn, y0, y1, yn};
|
||||
|
||||
const NaN: float = 0.0/0.0;
|
||||
|
||||
@ -410,18 +419,16 @@ fn sin(x: float) -> float { f64::sin(x as f64) as float }
|
||||
fn cos(x: float) -> float { f64::cos(x as f64) as float }
|
||||
fn tan(x: float) -> float { f64::tan(x as f64) as float }
|
||||
|
||||
mod extensions {
|
||||
impl num of num for float {
|
||||
fn add(&&other: float) -> float { ret self + other; }
|
||||
fn sub(&&other: float) -> float { ret self - other; }
|
||||
fn mul(&&other: float) -> float { ret self * other; }
|
||||
fn div(&&other: float) -> float { ret self / other; }
|
||||
fn modulo(&&other: float) -> float { ret self % other; }
|
||||
fn neg() -> float { ret -self; }
|
||||
impl num of num::num for float {
|
||||
fn add(&&other: float) -> float { ret self + other; }
|
||||
fn sub(&&other: float) -> float { ret self - other; }
|
||||
fn mul(&&other: float) -> float { ret self * other; }
|
||||
fn div(&&other: float) -> float { ret self / other; }
|
||||
fn modulo(&&other: float) -> float { ret self % other; }
|
||||
fn neg() -> float { ret -self; }
|
||||
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> float { ret n as float; }
|
||||
}
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> float { ret n as float; }
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -519,7 +526,7 @@ fn test_to_str_inf() {
|
||||
|
||||
#[test]
|
||||
fn test_ifaces() {
|
||||
fn test<U:num>(ten: U) {
|
||||
fn test<U:num::num>(ten: U) {
|
||||
assert (ten.to_int() == 10);
|
||||
|
||||
let two = ten.from_int(2);
|
||||
|
@ -1,6 +1,5 @@
|
||||
import T = inst::T;
|
||||
import cmp::{eq, ord};
|
||||
import num::num;
|
||||
|
||||
export min_value, max_value;
|
||||
export min, max;
|
||||
@ -12,7 +11,7 @@ export range;
|
||||
export compl;
|
||||
export abs;
|
||||
export parse_buf, from_str, to_str, to_str_bytes, str;
|
||||
export ord, eq, extensions;
|
||||
export num, ord, eq;
|
||||
|
||||
const min_value: T = -1 as T << (inst::bits - 1 as T);
|
||||
const max_value: T = min_value - 1 as T;
|
||||
@ -124,18 +123,16 @@ impl eq of eq for T {
|
||||
}
|
||||
}
|
||||
|
||||
mod extensions {
|
||||
impl num of num::num for T {
|
||||
fn add(&&other: T) -> T { ret self + other; }
|
||||
fn sub(&&other: T) -> T { ret self - other; }
|
||||
fn mul(&&other: T) -> T { ret self * other; }
|
||||
fn div(&&other: T) -> T { ret self / other; }
|
||||
fn modulo(&&other: T) -> T { ret self % other; }
|
||||
fn neg() -> T { ret -self; }
|
||||
impl num of num::num for T {
|
||||
fn add(&&other: T) -> T { ret self + other; }
|
||||
fn sub(&&other: T) -> T { ret self - other; }
|
||||
fn mul(&&other: T) -> T { ret self * other; }
|
||||
fn div(&&other: T) -> T { ret self / other; }
|
||||
fn modulo(&&other: T) -> T { ret self % other; }
|
||||
fn neg() -> T { ret -self; }
|
||||
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> T { ret n as T; }
|
||||
}
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> T { ret n as T; }
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import T = inst::T;
|
||||
import cmp::{eq, ord};
|
||||
import num::num;
|
||||
|
||||
export min_value, max_value;
|
||||
export min, max;
|
||||
@ -12,7 +11,7 @@ export range;
|
||||
export compl;
|
||||
export to_str, to_str_bytes;
|
||||
export from_str, from_str_radix, str, parse_buf;
|
||||
export ord, eq, extensions;
|
||||
export num, ord, eq;
|
||||
|
||||
const min_value: T = 0 as T;
|
||||
const max_value: T = 0 as T - 1 as T;
|
||||
@ -65,18 +64,16 @@ impl eq of eq for T {
|
||||
}
|
||||
}
|
||||
|
||||
mod extensions {
|
||||
impl num of num::num for T {
|
||||
fn add(&&other: T) -> T { ret self + other; }
|
||||
fn sub(&&other: T) -> T { ret self - other; }
|
||||
fn mul(&&other: T) -> T { ret self * other; }
|
||||
fn div(&&other: T) -> T { ret self / other; }
|
||||
fn modulo(&&other: T) -> T { ret self % other; }
|
||||
fn neg() -> T { ret -self; }
|
||||
impl num of num::num for T {
|
||||
fn add(&&other: T) -> T { ret self + other; }
|
||||
fn sub(&&other: T) -> T { ret self - other; }
|
||||
fn mul(&&other: T) -> T { ret self * other; }
|
||||
fn div(&&other: T) -> T { ret self / other; }
|
||||
fn modulo(&&other: T) -> T { ret self % other; }
|
||||
fn neg() -> T { ret -self; }
|
||||
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> T { ret n as T; }
|
||||
}
|
||||
fn to_int() -> int { ret self as int; }
|
||||
fn from_int(n: int) -> T { ret n as T; }
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
|
@ -1,23 +1,25 @@
|
||||
|
||||
|
||||
// This file is intended to test only that methods are automatically
|
||||
// reachable for each numeric type, for each exported impl, with no imports
|
||||
// necessary. Testing the methods of the impls is done within the source
|
||||
// file for each numeric type.
|
||||
fn main() {
|
||||
// extensions::num
|
||||
// num
|
||||
assert 15.add(6) == 21;
|
||||
assert 15i8.add(6i8) == 21i8;
|
||||
assert 15i16.add(6i16) == 21i16;
|
||||
assert 15i32.add(6i32) == 21i32;
|
||||
assert 15i64.add(6i64) == 21i64;
|
||||
|
||||
// extensions::num
|
||||
// num
|
||||
assert 15u.add(6u) == 21u;
|
||||
assert 15u8.add(6u8) == 21u8;
|
||||
assert 15u16.add(6u16) == 21u16;
|
||||
assert 15u32.add(6u32) == 21u32;
|
||||
assert 15u64.add(6u64) == 21u64;
|
||||
|
||||
// extensions::num
|
||||
// num
|
||||
assert 10f.to_int() == 10;
|
||||
assert 10f32.to_int() == 10;
|
||||
assert 10f64.to_int() == 10;
|
||||
|
Loading…
Reference in New Issue
Block a user