-1

i was reading a book , and encountered this

Arithmetic in JavaScript does not raise errors in cases of overflow, underflow, or division by zero. When the result of a numeric operation is larger than the largest representable number (overflow), the result is a special infinity value, Infinity. Similarly, when the absolute value of a negative value becomes larger than the absolute value of the largest representable negative number, the result is negative infinity, - Infinity.

how is it possible that the result of a absolute value of a negative number result in a negative number

1 Answer 1

1

That's not what it says. if |x| > |largest representable negative number| => -infinity so if -10 is the largest representable negative number and x is 11 then the result is -infinity

Sign up to request clarification or add additional context in comments.

5 Comments

is there a rational reason behind this
I also noticed that >>Math.pow(-3,99) //-1.7179250691067045e+47 . so -3 to the power of 99 resulted in a negative representable number (which should be turned to the absolute value of it when using Math.abs() , and that indeed what happens i.e.., >>Math.abs(Math.pow(-3,99)) //1.7179250691067045e+47 , but >>Math.pow(-3,999) //-Infinity , so here -3 to the power of 999 is an overflow/bypassed the largest representable number whoever that is , so when i get the absolute value of this one it should result in -infinity , but it doesn't >>Math.abs(Math.pow(-3,999)) //Infinity
@polendina an absolute number will never be negative. Math.abs(-infinity) === infinity
@polendina to me it seems rather rational that if an overflow is represented with infinity then an underflow would be -infinity
an absolute number will never be negative that's the cause of my confusion , as you explained that the author meant if |x| > |largest representable negative number| => -infinity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.