@@ -2197,6 +2197,50 @@ mod tests {
21972197 assert_eq ! ( Decimal256 :: MAX . checked_ceil( ) , Err ( RoundUpOverflowError ) ) ;
21982198 }
21992199
2200+ #[ test]
2201+ fn decimal256_to_uint_floor_works ( ) {
2202+ let d = Decimal256 :: from_str ( "12.000000000000000001" ) . unwrap ( ) ;
2203+ assert_eq ! ( d. to_uint_floor( ) , Uint256 :: from_u128( 12 ) ) ;
2204+ let d = Decimal256 :: from_str ( "12.345" ) . unwrap ( ) ;
2205+ assert_eq ! ( d. to_uint_floor( ) , Uint256 :: from_u128( 12 ) ) ;
2206+ let d = Decimal256 :: from_str ( "12.999" ) . unwrap ( ) ;
2207+ assert_eq ! ( d. to_uint_floor( ) , Uint256 :: from_u128( 12 ) ) ;
2208+
2209+ let d = Decimal256 :: from_str ( "75.0" ) . unwrap ( ) ;
2210+ assert_eq ! ( d. to_uint_floor( ) , Uint256 :: from_u128( 75 ) ) ;
2211+ let d = Decimal256 :: from_str ( "0.0" ) . unwrap ( ) ;
2212+ assert_eq ! ( d. to_uint_floor( ) , Uint256 :: from_u128( 0 ) ) ;
2213+
2214+ let d = Decimal256 :: MAX ;
2215+ assert_eq ! (
2216+ d. to_uint_floor( ) ,
2217+ Uint256 :: from_str( "115792089237316195423570985008687907853269984665640564039457" )
2218+ . unwrap( )
2219+ ) ;
2220+ }
2221+
2222+ #[ test]
2223+ fn decimal256_to_uint_ceil_works ( ) {
2224+ let d = Decimal256 :: from_str ( "12.000000000000000001" ) . unwrap ( ) ;
2225+ assert_eq ! ( d. to_uint_ceil( ) , Uint256 :: from_u128( 13 ) ) ;
2226+ let d = Decimal256 :: from_str ( "12.345" ) . unwrap ( ) ;
2227+ assert_eq ! ( d. to_uint_ceil( ) , Uint256 :: from_u128( 13 ) ) ;
2228+ let d = Decimal256 :: from_str ( "12.999" ) . unwrap ( ) ;
2229+ assert_eq ! ( d. to_uint_ceil( ) , Uint256 :: from_u128( 13 ) ) ;
2230+
2231+ let d = Decimal256 :: from_str ( "75.0" ) . unwrap ( ) ;
2232+ assert_eq ! ( d. to_uint_ceil( ) , Uint256 :: from_u128( 75 ) ) ;
2233+ let d = Decimal256 :: from_str ( "0.0" ) . unwrap ( ) ;
2234+ assert_eq ! ( d. to_uint_ceil( ) , Uint256 :: from_u128( 0 ) ) ;
2235+
2236+ let d = Decimal256 :: MAX ;
2237+ assert_eq ! (
2238+ d. to_uint_ceil( ) ,
2239+ Uint256 :: from_str( "115792089237316195423570985008687907853269984665640564039458" )
2240+ . unwrap( )
2241+ ) ;
2242+ }
2243+
22002244 #[ test]
22012245 fn decimal256_partial_eq ( ) {
22022246 let test_cases = [
0 commit comments