|
68 | 68 | use crate::RangeCheck; |
69 | 69 | #[allow(unused_imports)] |
70 | 70 | use crate::array::{ArrayTrait, SpanTrait}; |
| 71 | +use crate::internal::OptionRev; |
71 | 72 | #[feature("bounded-int-utils")] |
72 | | -use crate::internal::bounded_int::{downcast, upcast}; |
| 73 | +use crate::internal::bounded_int::{self, downcast, upcast}; |
73 | 74 | use crate::option::OptionTrait; |
74 | 75 | use crate::result::ResultTrait; |
75 | 76 | use crate::traits::{BitAnd, BitNot, BitOr, BitXor, Default, Felt252DictValue, Into, TryInto}; |
@@ -1210,10 +1211,9 @@ pub fn u256_wide_mul(a: u256, b: u256) -> u512 nopanic { |
1210 | 1211 |
|
1211 | 1212 | /// Helper function for implementation of `u256_wide_mul`. |
1212 | 1213 | /// Used for adding two u128s and receiving a BoundedInt for the carry result. |
1213 | | -#[feature("bounded-int-utils")] |
1214 | 1214 | pub(crate) fn u128_add_with_bounded_int_carry( |
1215 | 1215 | a: u128, b: u128, |
1216 | | -) -> (u128, crate::internal::bounded_int::BoundedInt<0, 1>) nopanic { |
| 1216 | +) -> (u128, bounded_int::BoundedInt<0, 1>) nopanic { |
1217 | 1217 | match u128_overflowing_add(a, b) { |
1218 | 1218 | Ok(v) => (v, 0), |
1219 | 1219 | Err(v) => (v, 1), |
@@ -1981,12 +1981,11 @@ impl I8Sub of Sub<i8> { |
1981 | 1981 |
|
1982 | 1982 | impl I8Neg of Neg<i8> { |
1983 | 1983 | #[inline] |
1984 | | - #[feature("bounded-int-utils")] |
1985 | 1984 | fn neg(a: i8) -> i8 { |
1986 | | - let core::internal::OptionRev::Some(a) = core::internal::bounded_int::trim_min(a) else { |
1987 | | - crate::panic_with_felt252('i8_neg Underflow'); |
1988 | | - }; |
1989 | | - upcast(core::internal::bounded_int::NegateHelper::negate(a)) |
| 1985 | + match bounded_int::trim_min(a) { |
| 1986 | + OptionRev::Some(a) => upcast(bounded_int::NegateHelper::negate(a)), |
| 1987 | + OptionRev::None => crate::panic_with_felt252('i8_neg Underflow'), |
| 1988 | + } |
1990 | 1989 | } |
1991 | 1990 | } |
1992 | 1991 |
|
@@ -2071,12 +2070,11 @@ impl I16Sub of Sub<i16> { |
2071 | 2070 |
|
2072 | 2071 | impl I16Neg of Neg<i16> { |
2073 | 2072 | #[inline] |
2074 | | - #[feature("bounded-int-utils")] |
2075 | 2073 | fn neg(a: i16) -> i16 { |
2076 | | - let core::internal::OptionRev::Some(a) = core::internal::bounded_int::trim_min(a) else { |
2077 | | - crate::panic_with_felt252('i16_neg Underflow'); |
2078 | | - }; |
2079 | | - upcast(core::internal::bounded_int::NegateHelper::negate(a)) |
| 2074 | + match bounded_int::trim_min(a) { |
| 2075 | + OptionRev::Some(a) => upcast(bounded_int::NegateHelper::negate(a)), |
| 2076 | + OptionRev::None => crate::panic_with_felt252('i16_neg Underflow'), |
| 2077 | + } |
2080 | 2078 | } |
2081 | 2079 | } |
2082 | 2080 |
|
@@ -2162,12 +2160,11 @@ impl I32Sub of Sub<i32> { |
2162 | 2160 |
|
2163 | 2161 | impl I32Neg of Neg<i32> { |
2164 | 2162 | #[inline] |
2165 | | - #[feature("bounded-int-utils")] |
2166 | 2163 | fn neg(a: i32) -> i32 { |
2167 | | - let core::internal::OptionRev::Some(a) = core::internal::bounded_int::trim_min(a) else { |
2168 | | - crate::panic_with_felt252('i32_neg Underflow'); |
2169 | | - }; |
2170 | | - upcast(core::internal::bounded_int::NegateHelper::negate(a)) |
| 2164 | + match bounded_int::trim_min(a) { |
| 2165 | + OptionRev::Some(a) => upcast(bounded_int::NegateHelper::negate(a)), |
| 2166 | + OptionRev::None => crate::panic_with_felt252('i32_neg Underflow'), |
| 2167 | + } |
2171 | 2168 | } |
2172 | 2169 | } |
2173 | 2170 |
|
@@ -2253,12 +2250,11 @@ impl I64Sub of Sub<i64> { |
2253 | 2250 |
|
2254 | 2251 | impl I64Neg of Neg<i64> { |
2255 | 2252 | #[inline] |
2256 | | - #[feature("bounded-int-utils")] |
2257 | 2253 | fn neg(a: i64) -> i64 { |
2258 | | - let core::internal::OptionRev::Some(a) = core::internal::bounded_int::trim_min(a) else { |
2259 | | - crate::panic_with_felt252('i64_neg Underflow'); |
2260 | | - }; |
2261 | | - upcast(core::internal::bounded_int::NegateHelper::negate(a)) |
| 2254 | + match bounded_int::trim_min(a) { |
| 2255 | + OptionRev::Some(a) => upcast(bounded_int::NegateHelper::negate(a)), |
| 2256 | + OptionRev::None => crate::panic_with_felt252('i64_neg Underflow'), |
| 2257 | + } |
2262 | 2258 | } |
2263 | 2259 | } |
2264 | 2260 |
|
@@ -2349,21 +2345,19 @@ impl I128Sub of Sub<i128> { |
2349 | 2345 |
|
2350 | 2346 | impl I128Neg of Neg<i128> { |
2351 | 2347 | #[inline] |
2352 | | - #[feature("bounded-int-utils")] |
2353 | 2348 | fn neg(a: i128) -> i128 { |
2354 | | - let core::internal::OptionRev::Some(a) = core::internal::bounded_int::trim_min(a) else { |
2355 | | - crate::panic_with_felt252('i128_neg Underflow'); |
2356 | | - }; |
2357 | | - upcast(core::internal::bounded_int::NegateHelper::negate(a)) |
| 2349 | + match bounded_int::trim_min(a) { |
| 2350 | + OptionRev::Some(a) => upcast(bounded_int::NegateHelper::negate(a)), |
| 2351 | + OptionRev::None => crate::panic_with_felt252('i128_neg Underflow'), |
| 2352 | + } |
2358 | 2353 | } |
2359 | 2354 | } |
2360 | 2355 |
|
2361 | 2356 | impl I128Mul of Mul<i128> { |
2362 | 2357 | fn mul(lhs: i128, rhs: i128) -> i128 { |
2363 | 2358 | let (lhs_u127, lhs_neg) = lhs.abs_and_sign(); |
2364 | | - #[feature("bounded-int-utils")] |
2365 | | - let (rhs_u127, res_neg) = match core::internal::bounded_int::constrain::<i128, 0>(rhs) { |
2366 | | - Ok(lt0) => (upcast(core::internal::bounded_int::NegateHelper::negate(lt0)), !lhs_neg), |
| 2359 | + let (rhs_u127, res_neg) = match bounded_int::constrain::<i128, 0>(rhs) { |
| 2360 | + Ok(lt0) => (upcast(bounded_int::NegateHelper::negate(lt0)), !lhs_neg), |
2367 | 2361 | Err(ge0) => (upcast(ge0), lhs_neg), |
2368 | 2362 | }; |
2369 | 2363 | let res_as_u128 = lhs_u127 * rhs_u127; |
@@ -3384,50 +3378,45 @@ pub(crate) trait AbsAndSign<Signed, Unsigned> { |
3384 | 3378 | } |
3385 | 3379 |
|
3386 | 3380 | impl I8ToU8 of AbsAndSign<i8, u8> { |
3387 | | - #[feature("bounded-int-utils")] |
3388 | 3381 | fn abs_and_sign(self: i8) -> (u8, bool) { |
3389 | | - match core::internal::bounded_int::constrain::<i8, 0>(self) { |
3390 | | - Ok(lt0) => (upcast(core::internal::bounded_int::NegateHelper::negate(lt0)), true), |
| 3382 | + match bounded_int::constrain::<i8, 0>(self) { |
| 3383 | + Ok(lt0) => (upcast(bounded_int::NegateHelper::negate(lt0)), true), |
3391 | 3384 | Err(ge0) => (upcast(ge0), false), |
3392 | 3385 | } |
3393 | 3386 | } |
3394 | 3387 | } |
3395 | 3388 |
|
3396 | 3389 | impl I16ToU16 of AbsAndSign<i16, u16> { |
3397 | | - #[feature("bounded-int-utils")] |
3398 | 3390 | fn abs_and_sign(self: i16) -> (u16, bool) { |
3399 | | - match core::internal::bounded_int::constrain::<i16, 0>(self) { |
3400 | | - Ok(lt0) => (upcast(core::internal::bounded_int::NegateHelper::negate(lt0)), true), |
| 3391 | + match bounded_int::constrain::<i16, 0>(self) { |
| 3392 | + Ok(lt0) => (upcast(bounded_int::NegateHelper::negate(lt0)), true), |
3401 | 3393 | Err(ge0) => (upcast(ge0), false), |
3402 | 3394 | } |
3403 | 3395 | } |
3404 | 3396 | } |
3405 | 3397 |
|
3406 | 3398 | impl I32ToU32 of AbsAndSign<i32, u32> { |
3407 | | - #[feature("bounded-int-utils")] |
3408 | 3399 | fn abs_and_sign(self: i32) -> (u32, bool) { |
3409 | | - match core::internal::bounded_int::constrain::<i32, 0>(self) { |
3410 | | - Ok(lt0) => (upcast(core::internal::bounded_int::NegateHelper::negate(lt0)), true), |
| 3400 | + match bounded_int::constrain::<i32, 0>(self) { |
| 3401 | + Ok(lt0) => (upcast(bounded_int::NegateHelper::negate(lt0)), true), |
3411 | 3402 | Err(ge0) => (upcast(ge0), false), |
3412 | 3403 | } |
3413 | 3404 | } |
3414 | 3405 | } |
3415 | 3406 |
|
3416 | 3407 | impl I64ToU64 of AbsAndSign<i64, u64> { |
3417 | | - #[feature("bounded-int-utils")] |
3418 | 3408 | fn abs_and_sign(self: i64) -> (u64, bool) { |
3419 | | - match core::internal::bounded_int::constrain::<i64, 0>(self) { |
3420 | | - Ok(lt0) => (upcast(core::internal::bounded_int::NegateHelper::negate(lt0)), true), |
| 3409 | + match bounded_int::constrain::<i64, 0>(self) { |
| 3410 | + Ok(lt0) => (upcast(bounded_int::NegateHelper::negate(lt0)), true), |
3421 | 3411 | Err(ge0) => (upcast(ge0), false), |
3422 | 3412 | } |
3423 | 3413 | } |
3424 | 3414 | } |
3425 | 3415 |
|
3426 | 3416 | impl I128ToU128 of AbsAndSign<i128, u128> { |
3427 | | - #[feature("bounded-int-utils")] |
3428 | 3417 | fn abs_and_sign(self: i128) -> (u128, bool) { |
3429 | | - match core::internal::bounded_int::constrain::<i128, 0>(self) { |
3430 | | - Ok(lt0) => (upcast(core::internal::bounded_int::NegateHelper::negate(lt0)), true), |
| 3418 | + match bounded_int::constrain::<i128, 0>(self) { |
| 3419 | + Ok(lt0) => (upcast(bounded_int::NegateHelper::negate(lt0)), true), |
3431 | 3420 | Err(ge0) => (upcast(ge0), false), |
3432 | 3421 | } |
3433 | 3422 | } |
|
0 commit comments