-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing primitives for signed calculations, and some operations for unsigned calculations #1105
Comments
What's the problem/use case exactly? Are you suggesting a signed Int128 type that does string serialization in JSON and otherwise is a i128? There are a bunch of wrapping operations in Uint128 already: pub fn wrapping_add(self, other: Self) -> Self {
Self(self.0.wrapping_add(other.0))
}
pub fn wrapping_sub(self, other: Self) -> Self {
Self(self.0.wrapping_sub(other.0))
}
pub fn wrapping_mul(self, other: Self) -> Self {
Self(self.0.wrapping_mul(other.0))
}
pub fn wrapping_pow(self, other: u32) -> Self {
Self(self.0.wrapping_pow(other))
} I'm sure we are missing a ton of things, but what do you need most urgently? |
Note: we should probably do #1114 before tackling this, unless there's something urgent that needs added. |
For |
This is now tracked in #1186. cosmwasm-std 1.1 ships many of those additional implementations. Please comment there is something is still missing. |
If I'm not mistaken, there still isn't a primitive for signed integer. We currently use this type implemented by Margined protocol. @webmaster128 something worthwhile to be introduced into cosmwasm-std? |
Right. The big question is if such a signed integer should be a tuple (unsigned value, sign) or a "proper" signed integer that encodes the sign in the two's complement. I am slightly leaning to the later as I think an Int128 should be consistent with i128 in terms of range and behaviour. Could you create a dedicated ticket for that topic? |
There are no primitives for signed calculations in cosmwasm std, and there are not even "wrapping" operations to simulate those behavior. Not a problem for Uint128, as it can be converted to native u128, and then to i128, but it doesn't help with (de)serialization.
Also Uint256 (and probably Uint128) is missing modulo operation which is useful to have.
The text was updated successfully, but these errors were encountered: