The Signed Zero Identity

HardAcc. 42.1%
+60 XP 25

The Hidden Negative

In JavaScript, there are actually two zeros: 0 and -0. Standard comparison (===) treats them as equal (0 === -0 is true).

However, in advanced math or physics engines, you might need to know which is which. You can detect the difference by seeing how they interact with Infinity.

The Assignment

Your function receives a number val.

  1. Determine if the value is strictly Negative Zero (-0).
  2. Return true if it is -0, and false if it is 0 (positive zero) or any other number.

01EXAMPLE 1

Inputval = -0
Outputtrue

Explanation: Negative zero detected.

02EXAMPLE 2

Inputval = 0
Outputfalse

Explanation: Positive zero is not negative zero.

Constraints

  • Do not use string conversion.
  • Use the relationship between 1/n and Infinity.
MathLogicProfessional
JavaScript
Loading...
3 Hidden

Input Arguments

val0

Expected Output

true

Click RUN to test your solution