@@ -18,7 +18,7 @@ use std::from_str::FromStr;
18
18
struct mpz_struct {
19
19
_mp_alloc : c_int ,
20
20
_mp_size : c_int ,
21
- _mp_d : * c_void
21
+ _mp_d : * mut c_void
22
22
}
23
23
24
24
struct mpq_struct {
@@ -32,21 +32,21 @@ struct mpf_struct {
32
32
_mp_prec : c_int ,
33
33
_mp_size : c_int ,
34
34
_mp_exp : mp_exp_t ,
35
- _mp_d : * c_void
35
+ _mp_d : * mut c_void
36
36
}
37
37
38
38
struct gmp_randstate_struct {
39
39
_mp_seed : mpz_struct ,
40
40
_mp_alg : c_int ,
41
- _mp_algdata : * c_void
41
+ _mp_algdata : * mut c_void
42
42
}
43
43
44
44
type mp_bitcnt_t = c_ulong ;
45
- type mpz_srcptr = * mpz_struct ;
45
+ type mpz_srcptr = * const mpz_struct ;
46
46
type mpz_ptr = * mut mpz_struct ;
47
- type mpq_srcptr = * mpq_struct ;
47
+ type mpq_srcptr = * const mpq_struct ;
48
48
type mpq_ptr = * mut mpq_struct ;
49
- type mpf_srcptr = * mpf_struct ;
49
+ type mpf_srcptr = * const mpf_struct ;
50
50
type mpf_ptr = * mut mpf_struct ;
51
51
type gmp_randstate_t = * mut gmp_randstate_struct ;
52
52
@@ -56,12 +56,12 @@ extern "C" {
56
56
fn __gmpz_init2 ( x : mpz_ptr , n : mp_bitcnt_t ) ;
57
57
fn __gmpz_init_set ( rop : mpz_ptr , op : mpz_srcptr ) ;
58
58
fn __gmpz_init_set_ui ( rop : mpz_ptr , op : c_ulong ) ;
59
- fn __gmpz_init_set_str ( rop : mpz_ptr , str : * c_char , base : c_int ) -> c_int ;
59
+ fn __gmpz_init_set_str ( rop : mpz_ptr , str : * const c_char , base : c_int ) -> c_int ;
60
60
fn __gmpz_clear ( x : mpz_ptr ) ;
61
61
fn __gmpz_realloc2 ( x : mpz_ptr , n : mp_bitcnt_t ) ;
62
62
fn __gmpz_set ( rop : mpz_ptr , op : mpz_srcptr ) ;
63
- fn __gmpz_set_str ( rop : mpz_ptr , str : * c_char , base : c_int ) -> c_int ;
64
- fn __gmpz_get_str ( str : * mut c_char , base : c_int , op : mpz_srcptr ) -> * c_char ;
63
+ fn __gmpz_set_str ( rop : mpz_ptr , str : * const c_char , base : c_int ) -> c_int ;
64
+ fn __gmpz_get_str ( str : * mut c_char , base : c_int , op : mpz_srcptr ) -> * mut c_char ;
65
65
fn __gmpz_sizeinbase ( op : mpz_srcptr , base : c_int ) -> size_t ;
66
66
fn __gmpz_cmp ( op1 : mpz_srcptr , op2 : mpz_srcptr ) -> c_int ;
67
67
fn __gmpz_cmp_ui ( op1 : mpz_srcptr , op2 : c_ulong ) -> c_int ;
@@ -92,12 +92,12 @@ extern "C" {
92
92
fn __gmpz_lcm ( rop : mpz_ptr , op1 : mpz_srcptr , op2 : mpz_srcptr ) ;
93
93
fn __gmpz_invert ( rop : mpz_ptr , op1 : mpz_srcptr , op2 : mpz_srcptr ) -> c_int ;
94
94
fn __gmpz_import ( rop : mpz_ptr , count : size_t , order : c_int , size : size_t ,
95
- endian : c_int , nails : size_t , op : * c_void ) ;
95
+ endian : c_int , nails : size_t , op : * const c_void ) ;
96
96
fn __gmp_randinit_default ( state : gmp_randstate_t ) ;
97
97
fn __gmp_randinit_mt ( state : gmp_randstate_t ) ;
98
98
fn __gmp_randinit_lc_2exp ( state : gmp_randstate_t , a : mpz_srcptr , c : c_ulong , m2exp : mp_bitcnt_t ) ;
99
99
fn __gmp_randinit_lc_2exp_size ( state : gmp_randstate_t , size : mp_bitcnt_t ) ;
100
- fn __gmp_randinit_set ( state : gmp_randstate_t , op : * gmp_randstate_struct ) ;
100
+ fn __gmp_randinit_set ( state : gmp_randstate_t , op : * const gmp_randstate_struct ) ;
101
101
fn __gmp_randclear ( state : gmp_randstate_t ) ;
102
102
fn __gmp_randseed ( state : gmp_randstate_t , seed : mpz_srcptr ) ;
103
103
fn __gmp_randseed_ui ( state : gmp_randstate_t , seed : c_ulong ) ;
@@ -337,8 +337,8 @@ impl Ord for Mpz {
337
337
}
338
338
339
339
impl PartialOrd for Mpz {
340
- fn lt ( & self , other : & Mpz ) -> bool {
341
- self . cmp ( other) == Less
340
+ fn partial_cmp ( & self , other : & Mpz ) -> Option < Ordering > {
341
+ Some ( self . cmp ( other) )
342
342
}
343
343
}
344
344
@@ -424,15 +424,15 @@ impl FromPrimitive for Mpz {
424
424
unsafe {
425
425
let mut res = Mpz :: new ( ) ;
426
426
__gmpz_import ( & mut res. mpz , 1 , 1 , size_of :: < u64 > ( ) as size_t , 0 , 0 ,
427
- & other as * u64 as * c_void ) ;
427
+ & other as * const u64 as * const c_void ) ;
428
428
Some ( res)
429
429
}
430
430
}
431
431
fn from_i64 ( other : i64 ) -> Option < Mpz > {
432
432
unsafe {
433
433
let mut res = Mpz :: new ( ) ;
434
434
__gmpz_import ( & mut res. mpz , 1 , 1 , size_of :: < i64 > ( ) as size_t , 0 , 0 ,
435
- & other. abs ( ) as * i64 as * c_void ) ;
435
+ & other. abs ( ) as * const i64 as * const c_void ) ;
436
436
if other. is_negative ( ) {
437
437
__gmpz_neg ( & mut res. mpz , & res. mpz )
438
438
}
@@ -713,17 +713,13 @@ impl cmp::PartialEq for Mpq {
713
713
}
714
714
715
715
impl cmp:: PartialOrd for Mpq {
716
- fn lt ( & self , other : & Mpq ) -> bool {
717
- unsafe { __gmpq_cmp ( & self . mpq , & other. mpq ) < 0 }
718
- }
719
- fn le ( & self , other : & Mpq ) -> bool {
720
- unsafe { __gmpq_cmp ( & self . mpq , & other. mpq ) <= 0 }
721
- }
722
- fn gt ( & self , other : & Mpq ) -> bool {
723
- unsafe { __gmpq_cmp ( & self . mpq , & other. mpq ) > 0 }
724
- }
725
- fn ge ( & self , other : & Mpq ) -> bool {
726
- unsafe { __gmpq_cmp ( & self . mpq , & other. mpq ) >= 0 }
716
+ fn partial_cmp ( & self , other : & Mpq ) -> Option < Ordering > {
717
+ match unsafe { __gmpq_cmp ( & self . mpq , & other. mpq ) } {
718
+ 0 => Some ( Equal ) ,
719
+ x if x < 0 => Some ( Less ) ,
720
+ x if x > 0 => Some ( Greater ) ,
721
+ _ => None ,
722
+ }
727
723
}
728
724
}
729
725
@@ -909,17 +905,13 @@ impl cmp::PartialEq for Mpf {
909
905
}
910
906
911
907
impl cmp:: PartialOrd for Mpf {
912
- fn lt ( & self , other : & Mpf ) -> bool {
913
- unsafe { __gmpf_cmp ( & self . mpf , & other. mpf ) < 0 }
914
- }
915
- fn le ( & self , other : & Mpf ) -> bool {
916
- unsafe { __gmpf_cmp ( & self . mpf , & other. mpf ) <= 0 }
917
- }
918
- fn gt ( & self , other : & Mpf ) -> bool {
919
- unsafe { __gmpf_cmp ( & self . mpf , & other. mpf ) > 0 }
920
- }
921
- fn ge ( & self , other : & Mpf ) -> bool {
922
- unsafe { __gmpf_cmp ( & self . mpf , & other. mpf ) >= 0 }
908
+ fn partial_cmp ( & self , other : & Mpf ) -> Option < Ordering > {
909
+ match unsafe { __gmpf_cmp ( & self . mpf , & other. mpf ) } {
910
+ 0 => Some ( Equal ) ,
911
+ x if x < 0 => Some ( Less ) ,
912
+ x if x > 0 => Some ( Greater ) ,
913
+ _ => None ,
914
+ }
923
915
}
924
916
}
925
917
0 commit comments