@@ -852,6 +852,15 @@ macro_rules! impl_bigint_ops_primitive {
852
852
}
853
853
}
854
854
855
+ impl <' a> Add <$primitive> for & ' a BigRational {
856
+ type Output = BigRational ;
857
+
858
+ #[ inline]
859
+ fn add( self , rhs: $primitive) -> BigRational {
860
+ Ratio :: new( self . numer. clone( ) + BigInt :: from( rhs) , self . denom. clone( ) )
861
+ }
862
+ }
863
+
855
864
impl Sub <$primitive> for BigRational {
856
865
type Output = BigRational ;
857
866
@@ -861,6 +870,15 @@ macro_rules! impl_bigint_ops_primitive {
861
870
}
862
871
}
863
872
873
+ impl <' a> Sub <$primitive> for & ' a BigRational {
874
+ type Output = BigRational ;
875
+
876
+ #[ inline]
877
+ fn sub( self , rhs: $primitive) -> BigRational {
878
+ Ratio :: new( self . numer. clone( ) - BigInt :: from( rhs) , self . denom. clone( ) )
879
+ }
880
+ }
881
+
864
882
impl Mul <$primitive> for BigRational {
865
883
type Output = BigRational ;
866
884
@@ -870,6 +888,15 @@ macro_rules! impl_bigint_ops_primitive {
870
888
}
871
889
}
872
890
891
+ impl <' a> Mul <$primitive> for & ' a BigRational {
892
+ type Output = BigRational ;
893
+
894
+ #[ inline]
895
+ fn mul( self , rhs: $primitive) -> BigRational {
896
+ Ratio :: new( self . numer. clone( ) * BigInt :: from( rhs) , self . denom. clone( ) )
897
+ }
898
+ }
899
+
873
900
impl Div <$primitive> for BigRational {
874
901
type Output = BigRational ;
875
902
@@ -878,6 +905,15 @@ macro_rules! impl_bigint_ops_primitive {
878
905
Ratio :: new( self . numer, self . denom * BigInt :: from( rhs) )
879
906
}
880
907
}
908
+
909
+ impl <' a> Div <$primitive> for & ' a BigRational {
910
+ type Output = BigRational ;
911
+
912
+ #[ inline]
913
+ fn div( self , rhs: $primitive) -> BigRational {
914
+ Ratio :: new( self . numer. clone( ) , self . denom. clone( ) * BigInt :: from( rhs) )
915
+ }
916
+ }
881
917
} ;
882
918
}
883
919
@@ -1959,6 +1995,9 @@ mod test {
1959
1995
fn test_isize ( a : BigRational , b : isize , c : BigRational ) {
1960
1996
assert_eq ! ( a + b, c) ;
1961
1997
}
1998
+ fn test_isize_ref ( a : & BigRational , b : isize , c : BigRational ) {
1999
+ assert_eq ! ( a + b, c) ;
2000
+ }
1962
2001
fn test_usize ( a : BigRational , b : usize , c : BigRational ) {
1963
2002
assert_eq ! ( a + b, c) ;
1964
2003
}
@@ -1997,8 +2036,12 @@ mod test {
1997
2036
fn test_bigint ( a : BigRational , b : BigInt , c : BigRational ) {
1998
2037
assert_eq ! ( a + b, c) ;
1999
2038
}
2039
+ fn test_bigint_ref ( a : & BigRational , b : BigInt , c : BigRational ) {
2040
+ assert_eq ! ( a + b, c) ;
2041
+ }
2000
2042
2001
2043
test_isize ( to_big ( _1) , -2 , to_big ( _NEG1) ) ;
2044
+ test_isize_ref ( & to_big ( _1) , -2 , to_big ( _NEG1) ) ;
2002
2045
test_usize ( to_big ( _1) , 1 , to_big ( _2) ) ;
2003
2046
test_i8 ( to_big ( _1) , -2 , to_big ( _NEG1) ) ;
2004
2047
test_u8 ( to_big ( _1) , 1 , to_big ( _2) ) ;
@@ -2013,6 +2056,7 @@ mod test {
2013
2056
#[ cfg( has_i128) ]
2014
2057
test_u128 ( to_big ( _1) , 1 , to_big ( _2) ) ;
2015
2058
test_bigint ( to_big ( _1) , BigInt :: from ( 1 ) , to_big ( _2) ) ;
2059
+ test_bigint_ref ( & to_big ( _1) , BigInt :: from ( 1 ) , to_big ( _2) ) ;
2016
2060
}
2017
2061
2018
2062
#[ test]
@@ -2206,6 +2250,9 @@ mod test {
2206
2250
fn test_isize ( a : BigRational , b : isize , c : BigRational ) {
2207
2251
assert_eq ! ( a - b, c) ;
2208
2252
}
2253
+ fn test_isize_ref ( a : & BigRational , b : isize , c : BigRational ) {
2254
+ assert_eq ! ( a - b, c) ;
2255
+ }
2209
2256
fn test_usize ( a : BigRational , b : usize , c : BigRational ) {
2210
2257
assert_eq ! ( a - b, c) ;
2211
2258
}
@@ -2244,8 +2291,12 @@ mod test {
2244
2291
fn test_bigint ( a : BigRational , b : BigInt , c : BigRational ) {
2245
2292
assert_eq ! ( a - b, c) ;
2246
2293
}
2294
+ fn test_bigint_ref ( a : & BigRational , b : BigInt , c : BigRational ) {
2295
+ assert_eq ! ( a - b, c) ;
2296
+ }
2247
2297
2248
2298
test_isize ( to_big ( _2) , 1 , to_big ( _1) ) ;
2299
+ test_isize_ref ( & to_big ( _2) , 1 , to_big ( _1) ) ;
2249
2300
test_usize ( to_big ( _2) , 1 , to_big ( _1) ) ;
2250
2301
test_i8 ( to_big ( _2) , 1 , to_big ( _1) ) ;
2251
2302
test_u8 ( to_big ( _2) , 1 , to_big ( _1) ) ;
@@ -2260,6 +2311,7 @@ mod test {
2260
2311
#[ cfg( has_i128) ]
2261
2312
test_u128 ( to_big ( _2) , 1 , to_big ( _1) ) ;
2262
2313
test_bigint ( to_big ( _2) , BigInt :: from ( 1 ) , to_big ( _1) ) ;
2314
+ test_bigint_ref ( & to_big ( _2) , BigInt :: from ( 1 ) , to_big ( _1) ) ;
2263
2315
}
2264
2316
2265
2317
#[ test]
@@ -2453,6 +2505,9 @@ mod test {
2453
2505
fn test_isize ( a : BigRational , b : isize , c : BigRational ) {
2454
2506
assert_eq ! ( a * b, c) ;
2455
2507
}
2508
+ fn test_isize_ref ( a : & BigRational , b : isize , c : BigRational ) {
2509
+ assert_eq ! ( a * b, c) ;
2510
+ }
2456
2511
fn test_usize ( a : BigRational , b : usize , c : BigRational ) {
2457
2512
assert_eq ! ( a * b, c) ;
2458
2513
}
@@ -2491,8 +2546,12 @@ mod test {
2491
2546
fn test_bigint ( a : BigRational , b : BigInt , c : BigRational ) {
2492
2547
assert_eq ! ( a * b, c) ;
2493
2548
}
2549
+ fn test_bigint_ref ( a : & BigRational , b : BigInt , c : BigRational ) {
2550
+ assert_eq ! ( a * b, c) ;
2551
+ }
2494
2552
2495
2553
test_isize ( to_big ( _1_2) , -2 , to_big ( _NEG1) ) ;
2554
+ test_isize_ref ( & to_big ( _1_2) , -2 , to_big ( _NEG1) ) ;
2496
2555
test_usize ( to_big ( _1_2) , 2 , to_big ( _1) ) ;
2497
2556
test_i8 ( to_big ( _1_2) , -2 , to_big ( _NEG1) ) ;
2498
2557
test_u8 ( to_big ( _1_2) , 2 , to_big ( _1) ) ;
@@ -2507,6 +2566,7 @@ mod test {
2507
2566
#[ cfg( has_i128) ]
2508
2567
test_u128 ( to_big ( _1_2) , 2 , to_big ( _1) ) ;
2509
2568
test_bigint ( to_big ( _1_2) , BigInt :: from ( 2 ) , to_big ( _1) ) ;
2569
+ test_bigint_ref ( & to_big ( _1_2) , BigInt :: from ( 2 ) , to_big ( _1) ) ;
2510
2570
}
2511
2571
2512
2572
#[ test]
@@ -2700,6 +2760,9 @@ mod test {
2700
2760
fn test_isize ( a : BigRational , b : isize , c : BigRational ) {
2701
2761
assert_eq ! ( a / b, c) ;
2702
2762
}
2763
+ fn test_isize_ref ( a : & BigRational , b : isize , c : BigRational ) {
2764
+ assert_eq ! ( a / b, c) ;
2765
+ }
2703
2766
fn test_usize ( a : BigRational , b : usize , c : BigRational ) {
2704
2767
assert_eq ! ( a / b, c) ;
2705
2768
}
@@ -2738,8 +2801,12 @@ mod test {
2738
2801
fn test_bigint ( a : BigRational , b : BigInt , c : BigRational ) {
2739
2802
assert_eq ! ( a / b, c) ;
2740
2803
}
2804
+ fn test_bigint_ref ( a : & BigRational , b : BigInt , c : BigRational ) {
2805
+ assert_eq ! ( a / b, c) ;
2806
+ }
2741
2807
2742
2808
test_isize ( to_big ( _2) , -2isize , to_big ( _NEG1) ) ;
2809
+ test_isize_ref ( & to_big ( _2) , -2isize , to_big ( _NEG1) ) ;
2743
2810
test_usize ( to_big ( _2) , 2usize , to_big ( _1) ) ;
2744
2811
test_i8 ( to_big ( _2) , -2i8 , to_big ( _NEG1) ) ;
2745
2812
test_u8 ( to_big ( _2) , 2u8 , to_big ( _1) ) ;
@@ -2754,6 +2821,7 @@ mod test {
2754
2821
#[ cfg( has_i128) ]
2755
2822
test_u128 ( to_big ( _2) , 2 , to_big ( _1) ) ;
2756
2823
test_bigint ( to_big ( _2) , BigInt :: from ( 2 ) , to_big ( _1) ) ;
2824
+ test_bigint_ref ( & to_big ( _2) , BigInt :: from ( 2 ) , to_big ( _1) ) ;
2757
2825
}
2758
2826
2759
2827
#[ test]
0 commit comments