Handling Infinity

2 views
Skip to first unread message

Ernie Turner

unread,
Nov 6, 2009, 11:46:09 AM11/6/09
to Closure Compiler Discuss
I'm not sure if this is so much of a bug or not, but I was running the
Closure Compiler on the YUI library (as it is part of my core combined
JS file) and it gave me a 'divide by 0' error because of this line.

d=d>=0?d:1/0;

Which is obviously dividing by zero, but JavaScript handles this by
using the Infinity value. Is this something that is possible to fix?

Alan Leung

unread,
Nov 6, 2009, 2:11:33 PM11/6/09
to closure-comp...@googlegroups.com
How about

  d=d>=0?d:Infinity;

instead?

-Alan

Robert Bowdidge

unread,
Nov 6, 2009, 2:23:20 PM11/6/09
to closure-comp...@googlegroups.com

On Nov 6, 2009, at 11:11 AM, Alan Leung wrote:
> d=d>=0?d:Infinity;


That's 5 more characters! I see a compression opportunity. Perhaps
Closure Compiler should insist on Infinity being a literal to validate
intent, but convert it to 1<0 where possible (or to a shorter variable
name if one's available.)

Robert

Ernie Turner

unread,
Nov 6, 2009, 2:28:00 PM11/6/09
to Closure Compiler Discuss
I definitely agree that just using Infinity instead is a great
workaround. The problem is just that this is in the core YUI code and
I really don't want to change it and have to deal with the maintenance
when upgrading. Seems like maybe just a poor choice on behalf of the
YUI team. But then again, Robert is right, it is 5 more characters :).

bolinfest

unread,
Nov 6, 2009, 4:55:15 PM11/6/09
to Closure Compiler Discuss
True, but is it 5 more characters after gzip :)

I haven't tried submitting a patch to YUI before, but it sounds like
this would be worth trying to submit to benefit everyone.

Ernie Turner

unread,
Nov 6, 2009, 5:27:32 PM11/6/09
to Closure Compiler Discuss
It turns out they've since fixed this in YUI 2.8 (I'm currently using
2.7). Still, it seems like maybe a minor gotcha.
Reply all
Reply to author
Forward
0 new messages