@@ -213,6 +213,14 @@ fn dispatch_next<const POINT: bool, const NEG: bool, const HAS: bool, const BIG:
213
213
}
214
214
}
215
215
216
+ /// Dispatch the next non-digit byte:
217
+ ///
218
+ /// * POINT - a decimal point has been seen
219
+ /// * NEG - we've encountered a `-` and the number is negative
220
+ /// * HAS - a digit has been encountered (when HAS is false it's invalid)
221
+ /// * BIG - a number that uses 96 bits instead of only 64 bits
222
+ /// * FIRST - true if it is the first byte in the string
223
+ /// * ROUND - attempt to round underflow
216
224
#[ inline( never) ]
217
225
fn non_digit_dispatch_u64 <
218
226
const POINT : bool ,
@@ -347,6 +355,7 @@ fn handle_full_128<const POINT: bool, const NEG: bool, const ROUND: bool>(
347
355
let next = * next;
348
356
if POINT && scale >= 28 {
349
357
if ROUND {
358
+ // This is the call site
350
359
maybe_round ( data, next, scale, POINT , NEG )
351
360
} else {
352
361
Err ( Error :: Underflow )
@@ -699,6 +708,7 @@ mod test {
699
708
use crate :: Decimal ;
700
709
use arrayvec:: ArrayString ;
701
710
use core:: { fmt:: Write , str:: FromStr } ;
711
+ use futures:: StreamExt ;
702
712
703
713
#[ test]
704
714
fn display_does_not_overflow_max_capacity ( ) {
@@ -955,6 +965,40 @@ mod test {
955
965
) ;
956
966
}
957
967
968
+ #[ test]
969
+ fn character_at_rounding_position ( ) {
970
+ let tests = [
971
+ // 6 is at the rounding position, so we round up
972
+ (
973
+ "1.000_000_000_000_000_000_000_000_000_06" ,
974
+ Ok ( Decimal :: from_i128_with_scale (
975
+ 1_000_000_000_000_000_000_000_000_000_1 ,
976
+ 28 ,
977
+ ) ) ,
978
+ ) ,
979
+ // Decimal point is at the rounding position
980
+ (
981
+ "1_000_000_000_000_000_000_000_000_000_0.6" ,
982
+ Ok ( Decimal :: from_i128_with_scale (
983
+ 1_000_000_000_000_000_000_000_000_000_1 ,
984
+ 0 ,
985
+ ) ) ,
986
+ ) ,
987
+ // Placeholder is at the rounding position
988
+ (
989
+ "1.000_000_000_000_000_000_000_000_000_0_6" ,
990
+ Ok ( Decimal :: from_i128_with_scale (
991
+ 1_000_000_000_000_000_000_000_000_000_1 ,
992
+ 28 ,
993
+ ) ) ,
994
+ ) ,
995
+ ] ;
996
+
997
+ for ( index, ( input, expected) ) in tests. iter ( ) . enumerate ( ) {
998
+ assert_eq ! ( parse_str_radix_10( input) , * expected, "Test Index {}" , index) ;
999
+ }
1000
+ }
1001
+
958
1002
#[ test]
959
1003
fn from_str_edge_cases_1 ( ) {
960
1004
assert_eq ! ( parse_str_radix_10( "" ) , Err ( Error :: from( "Invalid decimal: empty" ) ) ) ;
0 commit comments