Add sixth "centered" division operator
|Reported by:||cowan||Owned by:||cowan|
|Component:||WG1 - Core||Keywords:|
From the Guile manual:
— Scheme Procedure: centered/ x y
— Scheme Procedure: centered-quotient x y
— Scheme Procedure: centered-remainder x y
These procedures accept two real numbers x and y, where the divisor y must be non-zero. centered-quotient returns the integer q and centered-remainder returns the real number r such that x = q*y + r and -|y/2| <= r < |y/2|. centered/ returns both q and r, and is more efficient than computing each separately.
Note that centered-quotient returns x/y rounded to the nearest integer. When x/y lies exactly half-way between two integers, the tie is broken according to the sign of y. If y > 0, ties are rounded toward positive infinity, otherwise they are rounded toward negative infinity. This is a consequence of the requirement that -|y/2| <= r < |y/2|.
Note that these operators are equivalent to the R6RS operators div0, mod0, and div0-and-mod0.
Change History (5)
comment:1 Changed 6 years ago by alexshinn
- Resolution set to fixed
- Status changed from new to closed
comment:2 Changed 6 years ago by cowan
- Resolution fixed deleted
- Status changed from closed to reopened
comment:4 Changed 5 years ago by cowan
- Owner changed from alexshinn to cowan
- Status changed from decided to writing