瀏覽代碼

Convert statics to constants

gifnksm 10 年之前
父節點
當前提交
2fe050c471
共有 3 個文件被更改,包括 21 次插入21 次删除
  1. 4 4
      src/bigint.rs
  2. 7 7
      src/complex.rs
  3. 10 10
      src/rational.rs

+ 4 - 4
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 }

+ 7 - 7
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() {

+ 10 - 10
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(