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

update documentation around the division operator #309

Merged
merged 1 commit into from
Aug 5, 2024
Merged
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
17 changes: 3 additions & 14 deletions docs/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,15 @@ Additionally, they do not have an intrinsic cost, since they are compiled to CLV
| + | `(+ A B ...)` | Adds multiple atoms. |
| - | `(- A B ...)` | Subtracts multiple atoms. |
| \* | `(* A B ...)` | Multiplies multiple atoms. |
| / | `(/ A B)` | Divides two atoms. |
| / | `(/ A B)` | Divides two atoms. Rounds towards negative |
| | | infinity. |
Comment on lines +36 to +37

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| divmod | `(divmod A B)` | Calculates quotient and remainder in cons pair. |

### Negative Division

:::info

The `/` operator cannot be used to divide negative numbers. Previously this worked, but used the wrong method of dividing negative integers. The operator was [soft-forked at block height 2,300,000](https://www.chia.net/2022/03/04/divided-we-fork.en.html) to prevent this.

You should use `divmod` instead in situations where you need to divide negative numbers.

For example:

<Runnable flavor='chialisp'>

```chialisp
(f (divmod -6 3))
```

</Runnable>
In earlier versions of Chia, the `/` operator produced incorrect rounding when used with negative numbers. It was disabled in a [soft-fork at block height 2,300,000](https://www.chia.net/2022/03/04/divided-we-fork.en.html). It was enabled again in the hard fork, with correct behavior. It always rounds towards negative infinity

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In earlier versions of Chia, the `/` operator produced incorrect rounding when used with negative numbers. It was disabled in a [soft-fork at block height 2,300,000](https://www.chia.net/2022/03/04/divided-we-fork.en.html). It was enabled again in the hard fork, with correct behavior. It always rounds towards negative infinity
In earlier versions of Chia, the `/` operator produced incorrect rounding when used with negative numbers. It was disabled in a [soft-fork at block height 2,300,000](https://www.chia.net/2022/03/04/divided-we-fork.en.html). It was enabled again in the hard fork, with correct behavior. It always rounds towards negative infinity.


:::

Expand Down