comparing two floats to see if they're both negative, or both positive

compare, floating-point, javascript

Solution

Multiply them together.

If the answer is positive then they are both the same sign.

If the answer is negative then they are of opposite sign.

If the answer is zero (within some value to take care of rounding error) then one or both are zero and you'll have to check them individually. You'll then have to decide whether 0 to be treated as positive or negative in your scenario.

Problem

Hay guys, i have 2 floats, which both comes from input boxes. I need to compare these 2 floats, if one is negative and one is positive thrown an error. If they're both positive, or both negative, thats fine. Any ideas? Thanks

Original source

Related problems