@@ -39,6 +39,23 @@ use std::ops::RemAssign;
39
39
use std:: ops:: Sub ;
40
40
use std:: ops:: SubAssign ;
41
41
42
+ pub trait IntoRationalExponent {
43
+ fn into_rational_exponent ( self ) -> Ratio < BigInt > ;
44
+ }
45
+
46
+ impl < T : IntoRationalExponent + Clone > IntoRationalExponent for & ' _ T {
47
+ fn into_rational_exponent ( self ) -> Ratio < BigInt > {
48
+ ( * self ) . clone ( ) . into_rational_exponent ( )
49
+ }
50
+ }
51
+
52
+ impl < N : Into < BigInt > , D : Into < BigInt > > IntoRationalExponent for ( N , D ) {
53
+ fn into_rational_exponent ( self ) -> Ratio < BigInt > {
54
+ let ( numer, denom) = self ;
55
+ Ratio :: new ( numer. into ( ) , denom. into ( ) )
56
+ }
57
+ }
58
+
42
59
#[ derive( Clone ) ]
43
60
pub struct RealAlgebraicNumberData {
44
61
pub minimal_polynomial : Polynomial < BigInt > ,
@@ -111,6 +128,12 @@ macro_rules! impl_from_int_or_ratio {
111
128
}
112
129
}
113
130
131
+ impl IntoRationalExponent for $t {
132
+ fn into_rational_exponent( self ) -> Ratio <BigInt > {
133
+ BigInt :: from( self ) . into( )
134
+ }
135
+ }
136
+
114
137
impl From <Ratio <$t>> for RealAlgebraicNumber {
115
138
fn from( value: Ratio <$t>) -> Self {
116
139
let ( numer, denom) = value. into( ) ;
@@ -127,6 +150,13 @@ macro_rules! impl_from_int_or_ratio {
127
150
)
128
151
}
129
152
}
153
+
154
+ impl IntoRationalExponent for Ratio <$t> {
155
+ fn into_rational_exponent( self ) -> Ratio <BigInt > {
156
+ let ( numer, denom) = self . into( ) ;
157
+ Ratio :: new_raw( numer. into( ) , denom. into( ) )
158
+ }
159
+ }
130
160
} ;
131
161
}
132
162
@@ -766,11 +796,11 @@ impl RealAlgebraicNumber {
766
796
)
767
797
}
768
798
}
769
- pub fn checked_into_pow < E : Into < Ratio < BigInt > > > ( self , exponent : E ) -> Option < Self > {
770
- Self :: checked_pow_impl ( Cow :: Owned ( self ) , exponent. into ( ) )
799
+ pub fn checked_into_pow < E : IntoRationalExponent > ( self , exponent : E ) -> Option < Self > {
800
+ Self :: checked_pow_impl ( Cow :: Owned ( self ) , exponent. into_rational_exponent ( ) )
771
801
}
772
- pub fn checked_pow < E : Into < Ratio < BigInt > > > ( & self , exponent : E ) -> Option < Self > {
773
- Self :: checked_pow_impl ( Cow :: Borrowed ( self ) , exponent. into ( ) )
802
+ pub fn checked_pow < E : IntoRationalExponent > ( & self , exponent : E ) -> Option < Self > {
803
+ Self :: checked_pow_impl ( Cow :: Borrowed ( self ) , exponent. into_rational_exponent ( ) )
774
804
}
775
805
}
776
806
@@ -1409,17 +1439,19 @@ impl<'a, 'b> Rem<&'a RealAlgebraicNumber> for &'b RealAlgebraicNumber {
1409
1439
}
1410
1440
}
1411
1441
1412
- impl < E : Into < Ratio < BigInt > > > Pow < E > for RealAlgebraicNumber {
1442
+ impl < E : IntoRationalExponent > Pow < E > for RealAlgebraicNumber {
1413
1443
type Output = RealAlgebraicNumber ;
1414
1444
fn pow ( self , exponent : E ) -> RealAlgebraicNumber {
1415
- self . checked_into_pow ( exponent) . expect ( "checked_pow failed" )
1445
+ self . checked_into_pow ( exponent. into_rational_exponent ( ) )
1446
+ . expect ( "checked_pow failed" )
1416
1447
}
1417
1448
}
1418
1449
1419
- impl < E : Into < Ratio < BigInt > > > Pow < E > for & ' _ RealAlgebraicNumber {
1450
+ impl < E : IntoRationalExponent > Pow < E > for & ' _ RealAlgebraicNumber {
1420
1451
type Output = RealAlgebraicNumber ;
1421
1452
fn pow ( self , exponent : E ) -> RealAlgebraicNumber {
1422
- self . checked_pow ( exponent) . expect ( "checked_pow failed" )
1453
+ self . checked_pow ( exponent. into_rational_exponent ( ) )
1454
+ . expect ( "checked_pow failed" )
1423
1455
}
1424
1456
}
1425
1457
0 commit comments