Expand description
unprim contains primitive types from 8 into 256 bit. it is unstable and not intended for production use.
use laron_primitives::*;
let a = U256::from(100);
let b = U256::from(2);
assert_eq!(a * b, 200u64.into());
Or you can use .into()
method to init the types.
use laron_primitives::*;
let a: U24 = 100u64.into();
let b: U24 = 2u64.into();
let c: u32 = (a * b).into();
assert_eq!(c, 200);
You can use macro to define new types. In example if you want to define a type with 512 bit, you can use the macro.
use laron_primitives::*;
define!(U512, 64, "512 bit");
let a = U512::from(100);
let b = U512::from(2);
let c = a * b;
assert_eq!(c, 200u64.into());
Modules§
Macros§
- bit_
size - byte_
size - define
- doc
- from_
prim - impl_
bit_ ops - impl_
def_ trait - impl_
math_ ops - impl_
maths - impl_
serde - impl_
shift - impl_
stringr
Structs§
- U24
- 24-bit unsigned integer represented as little-endian byte order.
- U40
- 40-bit unsigned integer represented as little-endian byte order.
- U48
- 48-bit unsigned integer represented as little-endian byte order.
- U56
- 56-bit unsigned integer represented as little-endian byte order.
- U72
- 72-bit unsigned integer represented as little-endian byte order.
- U80
- 80-bit unsigned integer represented as little-endian byte order.
- U88
- 88-bit unsigned integer represented as little-endian byte order.
- U96
- 96-bit unsigned integer represented as little-endian byte order.
- U104
- 104-bit unsigned integer represented as little-endian byte order.
- U112
- 112-bit unsigned integer represented as little-endian byte order.
- U120
- 120-bit unsigned integer represented as little-endian byte order.
- U136
- 136-bit unsigned integer represented as little-endian byte order.
- U144
- 144-bit unsigned integer represented as little-endian byte order.
- U152
- 152-bit unsigned integer represented as little-endian byte order.
- U160
- 160-bit unsigned integer represented as little-endian byte order.
- U168
- 168-bit unsigned integer represented as little-endian byte order.
- U176
- 176-bit unsigned integer represented as little-endian byte order.
- U184
- 184-bit unsigned integer represented as little-endian byte order.
- U192
- 192-bit unsigned integer represented as little-endian byte order.
- U200
- 200-bit unsigned integer represented as little-endian byte order.
- U208
- 208-bit unsigned integer represented as little-endian byte order.
- U216
- 216-bit unsigned integer represented as little-endian byte order.
- U224
- 224-bit unsigned integer represented as little-endian byte order.
- U232
- 232-bit unsigned integer represented as little-endian byte order.
- U240
- 240-bit unsigned integer represented as little-endian byte order.
- U248
- 248-bit unsigned integer represented as little-endian byte order.
- U256
- 256-bit unsigned integer represented as little-endian byte order.
Traits§
- Add
- The addition operator
+
. - AddAssign
- The addition assignment operator
+=
. - BitAnd
- The bitwise AND operator
&
. - BitAnd
Assign - The bitwise AND assignment operator
&=
. - BitOr
- The bitwise OR operator
|
. - BitOr
Assign - The bitwise OR assignment operator
|=
. - BitXor
- The bitwise XOR operator
^
. - BitXor
Assign - The bitwise XOR assignment operator
^=
. - Deserialize
- A data structure that can be deserialized from any data format supported by Serde.
- Div
- The division operator
/
. - DivAssign
- The division assignment operator
/=
. - FromStr
- Parse a value from a string
- Mul
- The multiplication operator
*
. - MulAssign
- The multiplication assignment operator
*=
. - Not
- The unary logical negation operator
!
. - Rem
- The remainder operator
%
. - RemAssign
- The remainder assignment operator
%=
. - Serialize
- A data structure that can be serialized into any data format supported by Serde.
- Shl
- The left shift operator
<<
. Note that because this trait is implemented for all integer types with multiple right-hand-side types, Rust’s type checker has special handling for_ << _
, setting the result type for integer operations to the type of the left-hand-side operand. This means that thougha << b
anda.shl(b)
are one and the same from an evaluation standpoint, they are different when it comes to type inference. - ShlAssign
- The left shift assignment operator
<<=
. - Shr
- The right shift operator
>>
. Note that because this trait is implemented for all integer types with multiple right-hand-side types, Rust’s type checker has special handling for_ >> _
, setting the result type for integer operations to the type of the left-hand-side operand. This means that thougha >> b
anda.shr(b)
are one and the same from an evaluation standpoint, they are different when it comes to type inference. - ShrAssign
- The right shift assignment operator
>>=
. - Sub
- The subtraction operator
-
. - SubAssign
- The subtraction assignment operator
-=
.
Functions§
- add_
slice - Computes x += y where x and y is a slice. requires: len(x) >= len(y).
- div8
- Computes 16-bit division of two 8-bit numbers and return the quotient and remainder.
- div_
rem_ 2by1 - Devides <uh, ul> / d, returns the quotient and remainder. It use provided d’s reciprocal. Implementation is ported from https://github.com/holiman/uint250.
- mul8
- mul_
carry - mul_r
- reciprocal_
2by1 - Computes / d.
- sub_mul
- Computes x -= y * multiplier. requires: len(x) >= len(y).