News for hackers. Stuff that matters.
Re:Python, unlike C, has the mod operator always return a po... by olliej on Wednesday December 29, 2021 @05:53PM (#29731191)
The IEEE754 remainder function even beats C in that it can return a negative value even if both inputs are positive. IIRC the logic that leads to this is:

    remainder(a, b)
    n = round(a/b)
    return a - n * b
Because it rounds to get n, n * b can be greater than a :D

Even more fun as the original x87 implementation preceded IEEE754 its remainder operation (fprem, because it's technically a partial remainder) used truncation rather than rounding as that's the obvious behaviour. To support the IEEE754 specification they had to add fprem1 which performs a rounding operation instead. Hurrah! :D

Re:Python, unlike C, has the mod operator always return a po... by ThinBold on Thursday December 30, 2021 @03:58AM (#29734989)
What a beautiful way to shoot yourself in the foot
Re:Python, unlike C, has the mod operator always return a po... by olliej on Thursday December 30, 2021 @10:29PM (#29744559)
When I first encountered it it sent me down a path of paper reading that made me sad.

Even better, because it's defined in terms of rounding, it changes according to rounding mode :D