Skip to content
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

[gh-1117] add math modules. #2259

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions frameworks/move-stdlib/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@ version = "1.5.0"

[addresses]
std = "0x1"

[dev-addresses]
std = "0x1"
6 changes: 6 additions & 0 deletions frameworks/move-stdlib/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ This is the reference documentation of the Move standard library.
- [`0x1::signer`](signer.md#0x1_signer)
- [`0x1::string`](string.md#0x1_string)
- [`0x1::type_name`](type_name.md#0x1_type_name)
- [`0x1::u128`](u128.md#0x1_u128)
- [`0x1::u16`](u16.md#0x1_u16)
- [`0x1::u256`](u256.md#0x1_u256)
- [`0x1::u32`](u32.md#0x1_u32)
- [`0x1::u64`](u64.md#0x1_u64)
- [`0x1::u8`](u8.md#0x1_u8)
- [`0x1::vector`](vector.md#0x1_vector)


Expand Down
4 changes: 2 additions & 2 deletions frameworks/move-stdlib/doc/acl.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use a "set" instead when it's available in the language in the future.
The ACL already contains the address.


<pre><code><b>const</b> <a href="acl.md#0x1_acl_ECONTAIN">ECONTAIN</a>: u64 = 0;
<pre><code><b>const</b> <a href="acl.md#0x1_acl_ECONTAIN">ECONTAIN</a>: <a href="u64.md#0x1_u64">u64</a> = 0;
</code></pre>


Expand All @@ -55,7 +55,7 @@ The ACL already contains the address.
The ACL does not contain the address.


<pre><code><b>const</b> <a href="acl.md#0x1_acl_ENOT_CONTAIN">ENOT_CONTAIN</a>: u64 = 1;
<pre><code><b>const</b> <a href="acl.md#0x1_acl_ENOT_CONTAIN">ENOT_CONTAIN</a>: <a href="u64.md#0x1_u64">u64</a> = 1;
</code></pre>


Expand Down
20 changes: 10 additions & 10 deletions frameworks/move-stdlib/doc/ascii.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ An ASCII character.
An invalid ASCII character was encountered when creating an ASCII string.


<pre><code><b>const</b> <a href="ascii.md#0x1_ascii_EINVALID_ASCII_CHARACTER">EINVALID_ASCII_CHARACTER</a>: u64 = 65536;
<pre><code><b>const</b> <a href="ascii.md#0x1_ascii_EINVALID_ASCII_CHARACTER">EINVALID_ASCII_CHARACTER</a>: <a href="u64.md#0x1_u64">u64</a> = 65536;
</code></pre>


Expand All @@ -80,7 +80,7 @@ An invalid ASCII character was encountered when creating an ASCII string.
Convert a <code>byte</code> into a <code><a href="ascii.md#0x1_ascii_Char">Char</a></code> that is checked to make sure it is valid ASCII.


<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_char">char</a>(byte: u8): <a href="ascii.md#0x1_ascii_Char">ascii::Char</a>
<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_char">char</a>(byte: <a href="u8.md#0x1_u8">u8</a>): <a href="ascii.md#0x1_ascii_Char">ascii::Char</a>
</code></pre>


Expand All @@ -93,7 +93,7 @@ Convert a vector of bytes <code>bytes</code> into an <code><a href="ascii.md#0x1
<code>bytes</code> contains non-ASCII characters.


<pre><code><b>public</b> <b>fun</b> <a href="string.md#0x1_string">string</a>(bytes: <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="ascii.md#0x1_ascii_String">ascii::String</a>
<pre><code><b>public</b> <b>fun</b> <a href="string.md#0x1_string">string</a>(bytes: <a href="vector.md#0x1_vector">vector</a>&lt;<a href="u8.md#0x1_u8">u8</a>&gt;): <a href="ascii.md#0x1_ascii_String">ascii::String</a>
</code></pre>


Expand All @@ -107,7 +107,7 @@ Convert a vector of bytes <code>bytes</code> into an <code><a href="ascii.md#0x1
characters. Otherwise returns <code>None</code>.


<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_try_string">try_string</a>(bytes: <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;): <a href="option.md#0x1_option_Option">option::Option</a>&lt;<a href="ascii.md#0x1_ascii_String">ascii::String</a>&gt;
<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_try_string">try_string</a>(bytes: <a href="vector.md#0x1_vector">vector</a>&lt;<a href="u8.md#0x1_u8">u8</a>&gt;): <a href="option.md#0x1_option_Option">option::Option</a>&lt;<a href="ascii.md#0x1_ascii_String">ascii::String</a>&gt;
</code></pre>


Expand Down Expand Up @@ -153,7 +153,7 @@ Returns <code><b>false</b></code> otherwise. Not all <code><a href="ascii.md#0x1



<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_length">length</a>(<a href="string.md#0x1_string">string</a>: &<a href="ascii.md#0x1_ascii_String">ascii::String</a>): u64
<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_length">length</a>(<a href="string.md#0x1_string">string</a>: &<a href="ascii.md#0x1_ascii_String">ascii::String</a>): <a href="u64.md#0x1_u64">u64</a>
</code></pre>


Expand All @@ -165,7 +165,7 @@ Returns <code><b>false</b></code> otherwise. Not all <code><a href="ascii.md#0x1
Get the inner bytes of the <code><a href="string.md#0x1_string">string</a></code> as a reference


<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_as_bytes">as_bytes</a>(<a href="string.md#0x1_string">string</a>: &<a href="ascii.md#0x1_ascii_String">ascii::String</a>): &<a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_as_bytes">as_bytes</a>(<a href="string.md#0x1_string">string</a>: &<a href="ascii.md#0x1_ascii_String">ascii::String</a>): &<a href="vector.md#0x1_vector">vector</a>&lt;<a href="u8.md#0x1_u8">u8</a>&gt;
</code></pre>


Expand All @@ -177,7 +177,7 @@ Get the inner bytes of the <code><a href="string.md#0x1_string">string</a></code
Unpack the <code><a href="string.md#0x1_string">string</a></code> to get its backing bytes


<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_into_bytes">into_bytes</a>(<a href="string.md#0x1_string">string</a>: <a href="ascii.md#0x1_ascii_String">ascii::String</a>): <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_into_bytes">into_bytes</a>(<a href="string.md#0x1_string">string</a>: <a href="ascii.md#0x1_ascii_String">ascii::String</a>): <a href="vector.md#0x1_vector">vector</a>&lt;<a href="u8.md#0x1_u8">u8</a>&gt;
</code></pre>


Expand All @@ -189,7 +189,7 @@ Unpack the <code><a href="string.md#0x1_string">string</a></code> to get its bac
Unpack the <code>char</code> into its underlying byte.


<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_byte">byte</a>(char: <a href="ascii.md#0x1_ascii_Char">ascii::Char</a>): u8
<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_byte">byte</a>(char: <a href="ascii.md#0x1_ascii_Char">ascii::Char</a>): <a href="u8.md#0x1_u8">u8</a>
</code></pre>


Expand All @@ -201,7 +201,7 @@ Unpack the <code>char</code> into its underlying byte.
Returns <code><b>true</b></code> if <code>b</code> is a valid ASCII character. Returns <code><b>false</b></code> otherwise.


<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_is_valid_char">is_valid_char</a>(b: u8): bool
<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_is_valid_char">is_valid_char</a>(b: <a href="u8.md#0x1_u8">u8</a>): bool
</code></pre>


Expand All @@ -213,5 +213,5 @@ Returns <code><b>true</b></code> if <code>b</code> is a valid ASCII character. R
Returns <code><b>true</b></code> if <code>byte</code> is an printable ASCII character. Returns <code><b>false</b></code> otherwise.


<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_is_printable_char">is_printable_char</a>(byte: u8): bool
<pre><code><b>public</b> <b>fun</b> <a href="ascii.md#0x1_ascii_is_printable_char">is_printable_char</a>(byte: <a href="u8.md#0x1_u8">u8</a>): bool
</code></pre>
2 changes: 1 addition & 1 deletion frameworks/move-stdlib/doc/bcs.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ details on BCS.
Return the binary representation of <code>v</code> in BCS (Binary Canonical Serialization) format


<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x1_bcs_to_bytes">to_bytes</a>&lt;MoveValue&gt;(v: &MoveValue): <a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;
<pre><code><b>public</b> <b>fun</b> <a href="bcs.md#0x1_bcs_to_bytes">to_bytes</a>&lt;MoveValue&gt;(v: &MoveValue): <a href="vector.md#0x1_vector">vector</a>&lt;<a href="u8.md#0x1_u8">u8</a>&gt;
</code></pre>


Expand Down
24 changes: 12 additions & 12 deletions frameworks/move-stdlib/doc/bit_vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
The provided index is out of bounds


<pre><code><b>const</b> <a href="bit_vector.md#0x1_bit_vector_EINDEX">EINDEX</a>: u64 = 131072;
<pre><code><b>const</b> <a href="bit_vector.md#0x1_bit_vector_EINDEX">EINDEX</a>: <a href="u64.md#0x1_u64">u64</a> = 131072;
</code></pre>


Expand All @@ -52,7 +52,7 @@ The provided index is out of bounds
An invalid length of bitvector was given


<pre><code><b>const</b> <a href="bit_vector.md#0x1_bit_vector_ELENGTH">ELENGTH</a>: u64 = 131073;
<pre><code><b>const</b> <a href="bit_vector.md#0x1_bit_vector_ELENGTH">ELENGTH</a>: <a href="u64.md#0x1_u64">u64</a> = 131073;
</code></pre>


Expand All @@ -62,7 +62,7 @@ An invalid length of bitvector was given
The maximum allowed bitvector size


<pre><code><b>const</b> <a href="bit_vector.md#0x1_bit_vector_MAX_SIZE">MAX_SIZE</a>: u64 = 1024;
<pre><code><b>const</b> <a href="bit_vector.md#0x1_bit_vector_MAX_SIZE">MAX_SIZE</a>: <a href="u64.md#0x1_u64">u64</a> = 1024;
</code></pre>


Expand All @@ -71,7 +71,7 @@ The maximum allowed bitvector size



<pre><code><b>const</b> <a href="bit_vector.md#0x1_bit_vector_WORD_SIZE">WORD_SIZE</a>: u64 = 1;
<pre><code><b>const</b> <a href="bit_vector.md#0x1_bit_vector_WORD_SIZE">WORD_SIZE</a>: <a href="u64.md#0x1_u64">u64</a> = 1;
</code></pre>


Expand All @@ -82,7 +82,7 @@ The maximum allowed bitvector size



<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_new">new</a>(length: u64): <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>
<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_new">new</a>(length: <a href="u64.md#0x1_u64">u64</a>): <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>
</code></pre>


Expand All @@ -94,7 +94,7 @@ The maximum allowed bitvector size
Set the bit at <code>bit_index</code> in the <code>bitvector</code> regardless of its previous state.


<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_set">set</a>(bitvector: &<b>mut</b> <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, bit_index: u64)
<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_set">set</a>(bitvector: &<b>mut</b> <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, bit_index: <a href="u64.md#0x1_u64">u64</a>)
</code></pre>


Expand All @@ -106,7 +106,7 @@ Set the bit at <code>bit_index</code> in the <code>bitvector</code> regardless o
Unset the bit at <code>bit_index</code> in the <code>bitvector</code> regardless of its previous state.


<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_unset">unset</a>(bitvector: &<b>mut</b> <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, bit_index: u64)
<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_unset">unset</a>(bitvector: &<b>mut</b> <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, bit_index: <a href="u64.md#0x1_u64">u64</a>)
</code></pre>


Expand All @@ -119,7 +119,7 @@ Shift the <code>bitvector</code> left by <code>amount</code>. If <code>amount</c
bitvector's length the bitvector will be zeroed out.


<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_shift_left">shift_left</a>(bitvector: &<b>mut</b> <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, amount: u64)
<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_shift_left">shift_left</a>(bitvector: &<b>mut</b> <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, amount: <a href="u64.md#0x1_u64">u64</a>)
</code></pre>


Expand All @@ -132,7 +132,7 @@ Return the value of the bit at <code>bit_index</code> in the <code>bitvector</co
represents "1" and <code><b>false</b></code> represents a 0


<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_is_index_set">is_index_set</a>(bitvector: &<a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, bit_index: u64): bool
<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_is_index_set">is_index_set</a>(bitvector: &<a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, bit_index: <a href="u64.md#0x1_u64">u64</a>): bool
</code></pre>


Expand All @@ -144,7 +144,7 @@ represents "1" and <code><b>false</b></code> represents a 0
Return the length (number of usable bits) of this bitvector


<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_length">length</a>(bitvector: &<a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>): u64
<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_length">length</a>(bitvector: &<a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>): <a href="u64.md#0x1_u64">u64</a>
</code></pre>


Expand All @@ -158,7 +158,7 @@ including) <code>start_index</code> in the <code>bitvector</code>. If there is n
sequence, then <code>0</code> is returned.


<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_longest_set_sequence_starting_at">longest_set_sequence_starting_at</a>(bitvector: &<a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, start_index: u64): u64
<pre><code><b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_longest_set_sequence_starting_at">longest_set_sequence_starting_at</a>(bitvector: &<a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, start_index: <a href="u64.md#0x1_u64">u64</a>): <a href="u64.md#0x1_u64">u64</a>
</code></pre>


Expand All @@ -170,5 +170,5 @@ sequence, then <code>0</code> is returned.


<pre><code>#[verify_only]
<b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_shift_left_for_verification_only">shift_left_for_verification_only</a>(bitvector: &<b>mut</b> <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, amount: u64)
<b>public</b> <b>fun</b> <a href="bit_vector.md#0x1_bit_vector_shift_left_for_verification_only">shift_left_for_verification_only</a>(bitvector: &<b>mut</b> <a href="bit_vector.md#0x1_bit_vector_BitVector">bit_vector::BitVector</a>, amount: <a href="u64.md#0x1_u64">u64</a>)
</code></pre>
10 changes: 5 additions & 5 deletions frameworks/move-stdlib/doc/compare.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Utilities for comparing Move values based on their representation in BCS.



<pre><code><b>const</b> <a href="compare.md#0x1_compare_EQUAL">EQUAL</a>: u8 = 0;
<pre><code><b>const</b> <a href="compare.md#0x1_compare_EQUAL">EQUAL</a>: <a href="u8.md#0x1_u8">u8</a> = 0;
</code></pre>


Expand All @@ -32,7 +32,7 @@ Utilities for comparing Move values based on their representation in BCS.



<pre><code><b>const</b> <a href="compare.md#0x1_compare_GREATER_THAN">GREATER_THAN</a>: u8 = 2;
<pre><code><b>const</b> <a href="compare.md#0x1_compare_GREATER_THAN">GREATER_THAN</a>: <a href="u8.md#0x1_u8">u8</a> = 2;
</code></pre>


Expand All @@ -41,7 +41,7 @@ Utilities for comparing Move values based on their representation in BCS.



<pre><code><b>const</b> <a href="compare.md#0x1_compare_LESS_THAN">LESS_THAN</a>: u8 = 1;
<pre><code><b>const</b> <a href="compare.md#0x1_compare_LESS_THAN">LESS_THAN</a>: <a href="u8.md#0x1_u8">u8</a> = 1;
</code></pre>


Expand All @@ -63,7 +63,7 @@ following guarantees w.r.t the original values t1 and t2:
<code>compare::cmp&lt;T&gt;(t1, t2) != <a href="compare.md#0x1_compare_EQUAL">EQUAL</a></code> iff <code>t1 != t2</code>, where <code>==</code> and <code>!=</code> denote the Move
bytecode operations for polymorphic equality.
- for all primitive types <code>T</code> with <code>&lt;</code> and <code>&gt;</code> comparison operators exposed in Move bytecode
(<code>u8</code>, <code>u16</code>, <code>u32</code>, <code>u64</code>, <code>u128</code>, <code>u256</code>), we have
(<code><a href="u8.md#0x1_u8">u8</a></code>, <code><a href="u16.md#0x1_u16">u16</a></code>, <code><a href="u32.md#0x1_u32">u32</a></code>, <code><a href="u64.md#0x1_u64">u64</a></code>, <code><a href="u128.md#0x1_u128">u128</a></code>, <code><a href="u256.md#0x1_u256">u256</a></code>), we have
<code>compare_bcs_bytes(<a href="bcs.md#0x1_bcs">bcs</a>(t1), <a href="bcs.md#0x1_bcs">bcs</a>(t2)) == <a href="compare.md#0x1_compare_LESS_THAN">LESS_THAN</a></code> iff <code>t1 &lt; t2</code> and (similarly)
<code>compare_bcs_bytes(<a href="bcs.md#0x1_bcs">bcs</a>(t1), <a href="bcs.md#0x1_bcs">bcs</a>(t2)) == <a href="compare.md#0x1_compare_LESS_THAN">LESS_THAN</a></code> iff <code>t1 &gt; t2</code>.

Expand All @@ -81,5 +81,5 @@ Keep this in mind when using this function to compare addresses.
> native abstraction is needed in the prover framework.


<pre><code><b>public</b> <b>fun</b> <a href="compare.md#0x1_compare_cmp_bcs_bytes">cmp_bcs_bytes</a>(v1: &<a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;, v2: &<a href="vector.md#0x1_vector">vector</a>&lt;u8&gt;): u8
<pre><code><b>public</b> <b>fun</b> <a href="compare.md#0x1_compare_cmp_bcs_bytes">cmp_bcs_bytes</a>(v1: &<a href="vector.md#0x1_vector">vector</a>&lt;<a href="u8.md#0x1_u8">u8</a>&gt;, v2: &<a href="vector.md#0x1_vector">vector</a>&lt;<a href="u8.md#0x1_u8">u8</a>&gt;): <a href="u8.md#0x1_u8">u8</a>
</code></pre>
Loading
Loading