-4

Why Infinity equals to Infinity in Javascript? Please consider following examples:

Math.pow(10,1000)

The above will evaluate to Infinity.

Math.pow(11,1000)

The above will evaluate to infinity as well.

However in actual Math.pow(11,1000) is greater than Math.pow(10,1100). Please help me to understand the reason behind them being equal.

A B C D
  • 19
  • 3
  • infinity is not a rational number, you can't have twice infinity. It's infinite. – Liam Sep 08 '17 at 15:16
  • If Math.Pow(10,1000) equals infinity why would you think anything LARGER would resolve to anything else.... Infinity mesns never ending. – Qpirate Sep 08 '17 at 15:16
  • 1
    Or in the case of Javascript, it means 'too large to represent'. – Peter B Sep 08 '17 at 15:17
  • Possible duplicate of [What is JavaScript's highest integer value that a Number can go to without losing precision?](https://stackoverflow.com/questions/307179/what-is-javascripts-highest-integer-value-that-a-number-can-go-to-without-losin) – Liam Sep 08 '17 at 15:18

1 Answers1

2

They're equal because that's how Javascript represents numbers that are too large for it to represent effectively.

The MAX_VALUE property has a value of approximately 1.79E+308. Values larger than MAX_VALUE are represented as "Infinity".

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Infinity

Steven Goodman
  • 576
  • 3
  • 15