Struct cosmwasm_std::Int256
source · pub struct Int256(/* private fields */);
Expand description
An implementation of i256 that is using strings for JSON encoding/decoding, such that the full i256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.
§Examples
Use from
to create instances out of primitive uint types or new
to provide big
endian bytes:
let a = Int256::from(258u128);
let b = Int256::new([
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8,
0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8,
]);
assert_eq!(a, b);
Implementations§
source§impl Int256
impl Int256
pub const MAX: Int256 = _
pub const MIN: Int256 = _
sourcepub const fn new(value: [u8; 32]) -> Self
pub const fn new(value: [u8; 32]) -> Self
Creates a Int256(value) from a big endian representation. It’s just an alias for
from_be_bytes
.
sourcepub const fn from_i128(v: i128) -> Self
pub const fn from_i128(v: i128) -> Self
A conversion from i128
that, unlike the one provided by the From
trait,
can be used in a const
context.
pub const fn from_be_bytes(data: [u8; 32]) -> Self
pub const fn from_le_bytes(data: [u8; 32]) -> Self
sourcepub const fn to_be_bytes(self) -> [u8; 32]
pub const fn to_be_bytes(self) -> [u8; 32]
Returns a copy of the number as big endian bytes.
sourcepub const fn to_le_bytes(self) -> [u8; 32]
pub const fn to_le_bytes(self) -> [u8; 32]
Returns a copy of the number as little endian bytes.
pub const fn is_zero(&self) -> bool
pub const fn is_negative(&self) -> bool
pub fn pow(self, exp: u32) -> Self
sourcepub fn checked_multiply_ratio<A: Into<Self>, B: Into<Self>>(
&self,
numerator: A,
denominator: B
) -> Result<Self, CheckedMultiplyRatioError>
pub fn checked_multiply_ratio<A: Into<Self>, B: Into<Self>>( &self, numerator: A, denominator: B ) -> Result<Self, CheckedMultiplyRatioError>
Returns self * numerator / denominator
.
Due to the nature of the integer division involved, the result is always floored. E.g. 5 * 99/100 = 4.
pub fn checked_add(self, other: Self) -> Result<Self, OverflowError>
pub fn checked_sub(self, other: Self) -> Result<Self, OverflowError>
pub fn checked_mul(self, other: Self) -> Result<Self, OverflowError>
pub fn checked_pow(self, exp: u32) -> Result<Self, OverflowError>
pub fn checked_div(self, other: Self) -> Result<Self, DivisionError>
pub fn checked_div_euclid(self, other: Self) -> Result<Self, DivisionError>
pub fn checked_rem(self, other: Self) -> Result<Self, DivideByZeroError>
pub fn checked_shr(self, other: u32) -> Result<Self, OverflowError>
pub fn checked_shl(self, other: u32) -> Result<Self, OverflowError>
pub fn wrapping_add(self, other: Self) -> Self
pub fn wrapping_sub(self, other: Self) -> Self
pub fn wrapping_mul(self, other: Self) -> Self
pub fn wrapping_pow(self, other: u32) -> Self
pub fn saturating_add(self, other: Self) -> Self
pub fn saturating_sub(self, other: Self) -> Self
pub fn saturating_mul(self, other: Self) -> Self
pub fn saturating_pow(self, exp: u32) -> Self
pub const fn abs_diff(self, other: Self) -> Uint256
pub const fn abs(self) -> Self
pub const fn unsigned_abs(self) -> Uint256
Trait Implementations§
source§impl AddAssign<&Int256> for Int256
impl AddAssign<&Int256> for Int256
source§fn add_assign(&mut self, other: &Int256)
fn add_assign(&mut self, other: &Int256)
+=
operation. Read moresource§impl AddAssign for Int256
impl AddAssign for Int256
source§fn add_assign(&mut self, rhs: Int256)
fn add_assign(&mut self, rhs: Int256)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for Int256
impl<'de> Deserialize<'de> for Int256
source§fn deserialize<D>(deserializer: D) -> Result<Int256, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Int256, D::Error>where
D: Deserializer<'de>,
Deserialized from an integer string using base 10
source§impl Div<Int256> for SignedDecimal256
impl Div<Int256> for SignedDecimal256
source§impl DivAssign<&Int256> for Int256
impl DivAssign<&Int256> for Int256
source§fn div_assign(&mut self, other: &Int256)
fn div_assign(&mut self, other: &Int256)
/=
operation. Read moresource§impl DivAssign<Int256> for SignedDecimal256
impl DivAssign<Int256> for SignedDecimal256
source§fn div_assign(&mut self, rhs: Int256)
fn div_assign(&mut self, rhs: Int256)
/=
operation. Read moresource§impl DivAssign for Int256
impl DivAssign for Int256
source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresource§impl Fraction<Int256> for SignedDecimal256
impl Fraction<Int256> for SignedDecimal256
source§impl JsonSchema for Int256
impl JsonSchema for Int256
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moresource§impl MulAssign<&Int256> for Int256
impl MulAssign<&Int256> for Int256
source§fn mul_assign(&mut self, other: &Int256)
fn mul_assign(&mut self, other: &Int256)
*=
operation. Read moresource§impl MulAssign for Int256
impl MulAssign for Int256
source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresource§impl Ord for Int256
impl Ord for Int256
source§impl PartialEq<&Int256> for Int256
impl PartialEq<&Int256> for Int256
source§impl<'a> PartialEq<Int256> for &'a Int256
impl<'a> PartialEq<Int256> for &'a Int256
source§impl PartialEq for Int256
impl PartialEq for Int256
source§impl PartialOrd for Int256
impl PartialOrd for Int256
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl RemAssign<&Int256> for Int256
impl RemAssign<&Int256> for Int256
source§fn rem_assign(&mut self, other: &Int256)
fn rem_assign(&mut self, other: &Int256)
%=
operation. Read moresource§impl RemAssign for Int256
impl RemAssign for Int256
source§fn rem_assign(&mut self, rhs: Int256)
fn rem_assign(&mut self, rhs: Int256)
%=
operation. Read moresource§impl ShlAssign<&u32> for Int256
impl ShlAssign<&u32> for Int256
source§fn shl_assign(&mut self, other: &u32)
fn shl_assign(&mut self, other: &u32)
<<=
operation. Read moresource§impl ShlAssign<u32> for Int256
impl ShlAssign<u32> for Int256
source§fn shl_assign(&mut self, rhs: u32)
fn shl_assign(&mut self, rhs: u32)
<<=
operation. Read moresource§impl ShrAssign<&u32> for Int256
impl ShrAssign<&u32> for Int256
source§fn shr_assign(&mut self, other: &u32)
fn shr_assign(&mut self, other: &u32)
>>=
operation. Read moresource§impl ShrAssign<u32> for Int256
impl ShrAssign<u32> for Int256
source§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>=
operation. Read moresource§impl SubAssign<&Int256> for Int256
impl SubAssign<&Int256> for Int256
source§fn sub_assign(&mut self, other: &Int256)
fn sub_assign(&mut self, other: &Int256)
-=
operation. Read moresource§impl SubAssign for Int256
impl SubAssign for Int256
source§fn sub_assign(&mut self, rhs: Int256)
fn sub_assign(&mut self, rhs: Int256)
-=
operation. Read more