From 647902983eee1874a89890e798278a7cfc7cc3c6 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 5 Aug 2024 16:05:33 +0200 Subject: [PATCH] update documentation around the division operator. As of the hard fork, it supports negative operands --- docs/operators.md | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/docs/operators.md b/docs/operators.md index ea6a0152..8573d85e 100644 --- a/docs/operators.md +++ b/docs/operators.md @@ -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. | | 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: - - - -```chialisp -(f (divmod -6 3)) -``` - - +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 :::