@@ -962,7 +962,7 @@ impl TryFrom<Certificate> for pallas_primitives::conway::Certificate {
962962 . map_err ( CoreError :: msg) ?,
963963 pledge : pool_registration. pledge ,
964964 cost : pool_registration. cost ,
965- margin : RationalNumber :: from_number ( pool_registration. margin ) ,
965+ margin : RationalNumber :: from_f32 ( pool_registration. margin ) ,
966966 reward_account : Address :: from_bech32 ( & pool_registration. reward_address )
967967 . map_err ( CoreError :: msg) ?
968968 . to_vec ( )
@@ -1040,16 +1040,13 @@ impl TryFrom<Certificate> for pallas_primitives::conway::Certificate {
10401040 }
10411041}
10421042
1043- trait ToRationalNumber < A > {
1044- fn from_number ( n : A ) -> Self ;
1043+ trait ToRationalNumber {
1044+ fn from_f32 ( n : f32 ) -> Self ;
10451045}
10461046
1047- impl < A > ToRationalNumber < A > for RationalNumber
1048- where
1049- A : Into < f64 > ,
1050- {
1051- fn from_number ( n : A ) -> Self {
1052- let fraction = fraction:: Fraction :: from ( n. into ( ) ) ;
1047+ impl ToRationalNumber for RationalNumber {
1048+ fn from_f32 ( n : f32 ) -> Self {
1049+ let fraction = fraction:: Fraction :: from ( n) ;
10531050 Self {
10541051 numerator : * fraction. numer ( ) . unwrap ( ) as u64 ,
10551052 denominator : * fraction. denom ( ) . unwrap ( ) as u64 ,
@@ -1187,7 +1184,7 @@ impl<A> ConstrConversion<A> for Constr<A> {
11871184mod tests {
11881185 use std:: cmp:: Ordering ;
11891186
1190- use crate :: codec:: ConstrConversion ;
1187+ use crate :: codec:: { ConstrConversion , ToRationalNumber } ;
11911188 use fraction:: FromPrimitive ;
11921189 use pallas_primitives:: { Constr , PlutusData } ;
11931190
@@ -1285,4 +1282,13 @@ mod tests {
12851282 . unwrap ( ) ;
12861283 assert_eq ! ( original_num, -( num as i128 ) ) ;
12871284 }
1285+
1286+ #[ test]
1287+ fn test_fraction ( ) {
1288+ let rat = pallas_primitives:: RationalNumber :: from_f32 ( 0.015 ) ;
1289+ let frac = fraction:: Fraction :: from ( ( rat. numerator , rat. denominator ) ) ;
1290+ let f: f64 = frac. try_into ( ) . unwrap ( ) ;
1291+
1292+ assert_eq ! ( f, 0.015 ) ;
1293+ }
12881294}
0 commit comments