File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,17 +89,18 @@ mod tests {
8989 }
9090
9191 #[ test]
92- fn round_value_has_correct_decimal_places (
92+ fn round_value_error_within_half_unit (
9393 amount in 0.0_f64 ..1.0e8 ,
9494 unit in arb_btc_unit( ) ,
9595 ) {
9696 let rounded = unit. round_value( amount) ;
97- let factor = 10_f64 . powi( unit. decimal_places( ) . into( ) ) ;
98- let check = ( rounded * factor) . round( ) / factor;
99- let diff = ( rounded - check) . abs( ) ;
97+ let half_unit = 0.5 / 10_f64 . powi( unit. decimal_places( ) . into( ) ) ;
98+ // Allow a small extra tolerance for f64 representation at large magnitudes
99+ let tolerance = half_unit + amount. abs( ) * f64 :: EPSILON ;
100+ let error = ( rounded - amount) . abs( ) ;
100101 prop_assert!(
101- diff < 1.0e-10 ,
102- "round_value produced too many decimal places: {rounded} (expected {check}) "
102+ error <= tolerance ,
103+ "round_value({amount}) = {rounded}, error {error} exceeds half unit {half_unit} "
103104 ) ;
104105 }
105106 }
You can’t perform that action at this time.
0 commit comments