checked variants of I256 arithmetic functions
#1834
Replies: 2 comments 8 replies
-
|
Related to this, I am wondering why we even have non checked versions? By default we should have safe operations and only if explicitly requested we should have non-safe versions. That would be a better DX and follow the general idea of Stellar Smart contracts being a battery included platform with sane and sensible defaults. |
Beta Was this translation helpful? Give feedback.
-
|
I think @ozgunozerk's proposal at the top would require adding the following host functions, that mirror the existing For overflow-safe arithmetic, the new checked host functions would mirror the existing math operations but return Existing I256 Functions:
Existing U256 Functions:
Proposed I256 Checked Functions:
Proposed U256 Checked Functions:
Total: 16 new host functions (8 for each type) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Quoting from stellar/rs-soroban-sdk#1659:
What problem does your feature solve?
Right now, we don't have
checked_sub,checked_mul, etc. forI256custom type. This hinders the developers to write additional math libraries that may require thecheckedversions.In our case, we are writing a fixed_point_math library, and a
WADequivalent for Soroban. However, especially the error-handling part becomes a bit inconsistent due to lack ofcheckedvariants.Here is a code piece:
What would you like to see?
checkedvariants of all the arithmetic functionsWhat alternatives are there?
I saw that, behind the scenes,
env.i256_{operation}is used. For example:However, it is quite unintuitive, and even impossible to use the underlying
i256_{operation}functions as alternative.Impossible, due to:
Unintuitive, due to:
i256ValtypeResult, and we have to map theResultintoOptionchecked, which creates confusionI256Val, is reachable only throughself.to_val_type(), which adds additional frictionBeta Was this translation helpful? Give feedback.
All reactions