(precision: u8, input_scale: i8, decimal_places: i32)
| 40 | use std::sync::Arc; |
| 41 | |
| 42 | fn output_scale_for_decimal(precision: u8, input_scale: i8, decimal_places: i32) -> i8 { |
| 43 | // `decimal_places` controls the maximum output scale, but scale cannot exceed the input scale. |
| 44 | // |
| 45 | // For negative-scale decimals, allow further scale reduction to match negative `decimal_places` |
| 46 | // (e.g. scale -2 rounded to -3 becomes scale -3). This preserves fixed precision by |
| 47 | // representing the rounded result at a coarser scale. |
| 48 | if input_scale < 0 { |
| 49 | // Decimal scales must be within [-precision, precision] and fit in i8. For negative-scale |
| 50 | // decimals, allow rounding to move the output scale further negative, but cap it at |
| 51 | // `-precision` (beyond that, the rounded result is always 0). |
| 52 | let min_scale = -i32::from(precision); |
| 53 | let new_scale = i32::from(input_scale).min(decimal_places).max(min_scale); |
| 54 | return new_scale as i8; |
| 55 | } |
| 56 | |
| 57 | // The `min` ensures the result is always within i8 range because `input_scale` is i8. |
| 58 | let decimal_places = decimal_places.max(0); |
| 59 | i32::from(input_scale).min(decimal_places) as i8 |
| 60 | } |
| 61 | |
| 62 | fn normalize_decimal_places_for_decimal( |
| 63 | decimal_places: i32, |
no test coverage detected
searching dependent graphs…