News for hackers. Stuff that matters.
Re:Math.min(Math.max(num, min), max) by im3w1l on Thursday August 20, 2020 @02:38PM (#24226869)
So I tried a thing in python3.

    >>> max(float('nan'), 0)
    nan
    >>> max(0, float('nan'))
    0
Numpy works though

    >>> np.maximum(float('nan'), 0)
    nan
    >>> np.maximum(0, float('nan'))
    nan
Edit: Fixed numpy example.
Re:Math.min(Math.max(num, min), max) by rrobukef on Thursday August 20, 2020 @03:37PM (#24227767)
The functions minNum and maxNum ([IEEE 754-2008, 5.3.1, p19]) take two arguments and return the min and max, respectively. They have the special, distinguished property that “if exactly one argument is NaN, they return the other. If both are NaN they return NaN.”

Source: http://tom7.org/nand/nand.pdf

Edit: As of 2019, the formerly required minNum, maxNum, minNumMag, and maxNumMag in IEEE 754-2008 are now deleted due to their non-associativity. [https://en.wikipedia.org/wiki/IEEE_754#2019]

Re:Math.min(Math.max(num, min), max) by dr_zoidberg on Thursday August 20, 2020 @03:13PM (#24227423)
And for this particular use case, numpy has .clip(), that takes:

    np.clip(ndarray, lower_bound, upper_bound)
And handles NaNs correctly.