Skip to content

Commit

Permalink
update book, add changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
dark64 committed Nov 15, 2023
1 parent 11bee6a commit a11c1ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/1349-dark64
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement field division and remainder operations using euclidean division
36 changes: 19 additions & 17 deletions zokrates_book/src/language/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
The following table lists the precedence and associativity of all operators. Operators are listed top to bottom, in ascending precedence. Operators in the same cell have the same precedence. Operators are binary, unless the syntax is provided.


| Operator | Description | `field` | `u8/u16` `u32/u64` | `bool` | Associativity |
|--------------------------------------------|------------------------------------------------------------|------------------------------|-------------------------------|-----------------------------|---------------|
| `**`<br> | Power | &check;[^1] | &nbsp; | &nbsp; | Left |
| `+x`<br>`-x`<br>`!x`<br> | Positive<br>Negative<br>Negation<br> | &check;<br>&check;<br>&nbsp; | &check;<br>&check;<br>&check; | &nbsp;<br>&nbsp;<br>&check; | Right |
| `*`<br>`/`<br>`%`<br> | Multiplication<br> Division<br> Remainder<br> | &check;<br>&check;<br>&nbsp; | &check;<br>&check;<br>&check; | &nbsp;<br>&nbsp;<br>&nbsp; | Left |
| `+`<br>`-`<br> | Addition<br> Subtraction<br> | &check; | &check; | &nbsp; | Left |
| `<<`<br>`>>`<br> | Left shift<br> Right shift<br> | &nbsp; | &check;[^2] | &nbsp; | Left |
| `&` | Bitwise AND | &nbsp; | &check; | &nbsp; | Left |
| <code>&#124;</code> | Bitwise OR | &nbsp; | &check; | &nbsp; | Left |
| `^` | Bitwise XOR | &nbsp; | &check; | &nbsp; | Left |
| `>=`<br>`>`<br>`<=`<br>`<` | Greater or equal<br>Greater<br>Lower or equal<br>Lower<br> | &check;[^3] | &check; | &nbsp; | Left |
| `!=`<br>`==`<br> | Not Equal<br>Equal<br> | &check; | &check; | &check; | Left |
| `&&` | Boolean AND | &nbsp; | &nbsp; | &check; | Left |
| <code>&#124;&#124;</code> | Boolean OR | &nbsp; | &nbsp; | &check; | Left |
| `c ? x : y`<br><br>`if c { x } else { y }` | Conditional expression | &check; | &check; | &check; | Right |
| Operator | Description | `field` | `u8/u16` `u32/u64` | `bool` | Associativity |
|--------------------------------------------|------------------------------------------------------------|-----------------------------------|-------------------------------|-----------------------------|---------------|
| `**`<br> | Power | &check;[^1] | &nbsp; | &nbsp; | Left |
| `+x`<br>`-x`<br>`!x`<br> | Positive<br>Negative<br>Negation<br> | &check;<br>&check;<br>&nbsp; | &check;<br>&check;<br>&check; | &nbsp;<br>&nbsp;<br>&check; | Right |
| `*`<br>`/`<br>`%`<br> | Multiplication<br> Division<br> Remainder<br> | &check;<br>&check;[^2]<br>&check; | &check;<br>&check;<br>&check; | &nbsp;<br>&nbsp;<br>&nbsp; | Left |
| `+`<br>`-`<br> | Addition<br> Subtraction<br> | &check; | &check; | &nbsp; | Left |
| `<<`<br>`>>`<br> | Left shift<br> Right shift<br> | &nbsp; | &check;[^3] | &nbsp; | Left |
| `&` | Bitwise AND | &nbsp; | &check; | &nbsp; | Left |
| <code>&#124;</code> | Bitwise OR | &nbsp; | &check; | &nbsp; | Left |
| `^` | Bitwise XOR | &nbsp; | &check; | &nbsp; | Left |
| `>=`<br>`>`<br>`<=`<br>`<` | Greater or equal<br>Greater<br>Lower or equal<br>Lower<br> | &check;[^4] | &check; | &nbsp; | Left |
| `!=`<br>`==`<br> | Not Equal<br>Equal<br> | &check; | &check; | &check; | Left |
| `&&` | Boolean AND | &nbsp; | &nbsp; | &check; | Left |
| <code>&#124;&#124;</code> | Boolean OR | &nbsp; | &nbsp; | &check; | Left |
| `c ? x : y`<br><br>`if c { x } else { y }` | Conditional expression | &check; | &check; | &check; | Right |

[^1]: The exponent must be a compile-time constant of type `u32`

[^2]: The right operand must be a compile time constant of type `u32`
[^2]: Field division is defined as multiplication by the inverse modulo `p`. Use `\` to get the quotient of the integer division.

[^3]: If neither of the operands can be determined to be a compile-time constant, then we have a restriction: for the check `a < b`, if the field prime `p` is represented on `N` bits, `|a - b|` must fit in `N - 2` bits.
[^3]: The right operand must be a compile time constant of type `u32`

[^4]: If neither of the operands can be determined to be a compile-time constant, then we have a restriction: for the check `a < b`, if the field prime `p` is represented on `N` bits, `|a - b|` must fit in `N - 2` bits.
Failing to respect this condition will lead to a runtime error.

0 comments on commit a11c1ba

Please sign in to comment.