archives

« Bugzilla Issues Index

#3114 — Mathematical operations on infinities


For example, String.prototype.indexOf.

"aa".indexOf("a", +Infinity) will result in a _position_ argument of +Infinity. Then, "Let pos be ToInteger(position)" just means that pos = +Infinity as well, since ToInteger passes through those values. But step 9 then does max(pos, 0), and the clause on algorithm conventions says:

> Mathematical operations such as addition, subtraction, negation, multiplication, division, and the mathematical functions defined later in this clause should always be understood as computing exact mathematical results on mathematical real numbers, which do not include infinities and do not include a negative zero that is distinguished from positive zero.

So max() is not defined for handling a pos of +Infinity.

A similar problem occurs with Array.prototype.indexOf, which passes through infinities to abs().

This bug also appears in the ES5 spec.


This ties into the confusion where IsInteger(+∞) is false, but ToInteger(+∞) returns +∞.


It's also unclear whether you can say "if k > 0" without first separately handling the case where k is an infinity. Since > is a mathematical operation.

Another data point: V8 handles this much as you would expect, with its min(), max(), and abs() functions able to handle infinities, and its relational operators able to compare them. The path of least resistance here may indeed be to fix the math operations to handle infinities.


ToLength also has this problem: ToLength(+∞) passes the +∞ to min(len, 2^{53}-1).

I am increasingly convinced that the right thing to do is allow min/max/abs/etc. to work on infinities.


fixed in rev34 editor's draft

I made ToLength explicitly deal with +Infinity

also updated clause 5 to say that min/max accept +-Infinity

It's not clear that any other clause 5 functions need to.


fixed in rev34