From 2fe050c4713c516b660bd595ccf06a2e5cd42f2a Mon Sep 17 00:00:00 2001 From: gifnksm Date: Fri, 10 Oct 2014 22:50:22 +0900 Subject: [PATCH] Convert statics to constants --- src/bigint.rs | 8 ++++---- src/complex.rs | 14 +++++++------- src/rational.rs | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/bigint.rs b/src/bigint.rs index 96ea630..276b13f 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -75,7 +75,7 @@ pub type BigDigit = u32; /// size is the double of the size of `BigDigit`. pub type DoubleBigDigit = u64; -pub static ZERO_BIG_DIGIT: BigDigit = 0; +pub const ZERO_BIG_DIGIT: BigDigit = 0; static ZERO_VEC: [BigDigit, ..1] = [ZERO_BIG_DIGIT]; #[allow(non_snake_case)] @@ -84,10 +84,10 @@ pub mod BigDigit { use super::DoubleBigDigit; // `DoubleBigDigit` size dependent - pub static bits: uint = 32; + pub const bits: uint = 32; - pub static base: DoubleBigDigit = 1 << bits; - static lo_mask: DoubleBigDigit = (-1 as DoubleBigDigit) >> bits; + pub const base: DoubleBigDigit = 1 << bits; + const lo_mask: DoubleBigDigit = (-1 as DoubleBigDigit) >> bits; #[inline] fn get_hi(n: DoubleBigDigit) -> BigDigit { (n >> bits) as BigDigit } diff --git a/src/complex.rs b/src/complex.rs index 24c99a3..a0068e2 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -194,13 +194,13 @@ mod test { use std::num::{Zero, One, Float}; use std::hash::hash; - pub static _0_0i : Complex64 = Complex { re: 0.0, im: 0.0 }; - pub static _1_0i : Complex64 = Complex { re: 1.0, im: 0.0 }; - pub static _1_1i : Complex64 = Complex { re: 1.0, im: 1.0 }; - pub static _0_1i : Complex64 = Complex { re: 0.0, im: 1.0 }; - pub static _neg1_1i : Complex64 = Complex { re: -1.0, im: 1.0 }; - pub static _05_05i : Complex64 = Complex { re: 0.5, im: 0.5 }; - pub static all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i]; + pub const _0_0i : Complex64 = Complex { re: 0.0, im: 0.0 }; + pub const _1_0i : Complex64 = Complex { re: 1.0, im: 0.0 }; + pub const _1_1i : Complex64 = Complex { re: 1.0, im: 1.0 }; + pub const _0_1i : Complex64 = Complex { re: 0.0, im: 1.0 }; + pub const _neg1_1i : Complex64 = Complex { re: -1.0, im: 1.0 }; + pub const _05_05i : Complex64 = Complex { re: 0.5, im: 0.5 }; + pub const all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i]; #[test] fn test_consts() { diff --git a/src/rational.rs b/src/rational.rs index 2e13d5f..9fc04bf 100644 --- a/src/rational.rs +++ b/src/rational.rs @@ -401,16 +401,16 @@ mod test { use std::num; use std::i32; - pub static _0 : Rational = Ratio { numer: 0, denom: 1}; - pub static _1 : Rational = Ratio { numer: 1, denom: 1}; - pub static _2: Rational = Ratio { numer: 2, denom: 1}; - pub static _1_2: Rational = Ratio { numer: 1, denom: 2}; - pub static _3_2: Rational = Ratio { numer: 3, denom: 2}; - pub static _neg1_2: Rational = Ratio { numer: -1, denom: 2}; - pub static _1_3: Rational = Ratio { numer: 1, denom: 3}; - pub static _neg1_3: Rational = Ratio { numer: -1, denom: 3}; - pub static _2_3: Rational = Ratio { numer: 2, denom: 3}; - pub static _neg2_3: Rational = Ratio { numer: -2, denom: 3}; + pub const _0 : Rational = Ratio { numer: 0, denom: 1}; + pub const _1 : Rational = Ratio { numer: 1, denom: 1}; + pub const _2: Rational = Ratio { numer: 2, denom: 1}; + pub const _1_2: Rational = Ratio { numer: 1, denom: 2}; + pub const _3_2: Rational = Ratio { numer: 3, denom: 2}; + pub const _neg1_2: Rational = Ratio { numer: -1, denom: 2}; + pub const _1_3: Rational = Ratio { numer: 1, denom: 3}; + pub const _neg1_3: Rational = Ratio { numer: -1, denom: 3}; + pub const _2_3: Rational = Ratio { numer: 2, denom: 3}; + pub const _neg2_3: Rational = Ratio { numer: -2, denom: 3}; pub fn to_big(n: Rational) -> BigRational { Ratio::new(