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.
- Determine if the value is strictly Negative Zero (
-0). - Return
trueif it is-0, andfalseif it is0(positive zero) or any other number.
01EXAMPLE 1
Input
val = -0Output
trueExplanation: Negative zero detected.
02EXAMPLE 2
Input
val = 0Output
falseExplanation: Positive zero is not negative zero.
Constraints
- Do not use string conversion.
- Use the relationship between 1/n and Infinity.
MathLogicProfessional
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
val0
Expected Output
true
Click RUN to test your solution