0

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

polendina
  • 110
  • 3
  • 10

1 Answers1

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

Rune FS
  • 21,497
  • 7
  • 62
  • 96
  • is there a rational reason behind this – polendina Feb 15 '21 at 23:59
  • 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 Feb 16 '21 at 00:15
  • @polendina an absolute number will never be negative. `Math.abs(-infinity) === infinity` – Rune FS Feb 18 '21 at 10:48
  • @polendina to me it seems rather rational that if an overflow is represented with infinity then an underflow would be -infinity – Rune FS Feb 18 '21 at 10:49
  • `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` – polendina Feb 21 '21 at 12:38