Name for closer to zero? Math.min won't do, so what is better?

I’m doing a small project that involves placing a small square to designate a 90 angle, as sin and cos are used around the full range of a circle.

When that small square gets close to an axis I don’t want the square to overflow to the other side of the axis. As a result, Math.min doesn’t help here because we’re dealing with negative values too, and I’m wanting the value that’s closer to zero.

Currently I’m using a min magnitude function:

const minMag = (a, b) => Math.min(Math.abs(a), Math.abs(b)) === Math.abs(a)
    ? a
    : b;

Is there a name for what this represents better than minMag? Something else?

For anyone that’s curious, it’s for an animated trig functions graph over at http://codepen.io/pmw57/pen/YqmjgO

1 Like

I can’t think of any easier way to do it than the way you have.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.