49

How Javascript handles Infinity:

Infinity * 1 == Infinity
Infinity * 0 == NaN
Infinity / 0 == Infinity
0 / Infinity == 0
Infinity + Infinity == Infinity
Infinity - Infinity == NaN
Infinity / Infinity == NaN
NaN & Infinity == 0
NaN && Infinity == NaN
NaN || Infinity == Infinity
1 % Infinity == 1
Infinity << 1 == 0
Infinity >> 0 == 0
Infinity | 0 == 0
Infinity | Infinity == 0

That's kinda philosophical, isn't it?

Comments
  • 2
  • 0
    @DivByZerocouldnt I can't get it around my head in the philosophical level from:
    Infinity << 1 == 0
    ..
    down to the end.

    Why feeding Infity 1 or true equals 0 or false?
  • 3
    since when does x/x != 1? JS is fun.. 😂
  • 5
    Looks like they follow IEEE 754 pretty well.
  • 5
    @bioDan That no feeding, its the logical shift command. All bits of a number a shifted left or right by that command.
    Example 1 << 3 returns 8 because
    1 == 0000 0001 (== 1 Dezimal)
    1<<1 == 0000 0010 (== 2 Dezimal)
    1<<2 == 0000 0100 (== 4 Dezimal)
    1<<3 == 0000 1000 (== 8 Dezimal)
  • 1
    @DivByZero oh true yes, thanks. I got confused there 😕
  • 11
    @olback Infinity divided by infinity is also not well defined in math. If you calculate it with limits, you can make it approach any value. So for once this isn't on JavaScript
  • 4
    @olback IEEE 754, it specifies that infinity / infinity, 0 x infinty and infinity - infinity should be NaN.

    Most languages either stick to IEEE 754 or just use whatever the CPU is using (which will still be IEEE 754 unless you're running on some old mainframe)
  • 4
    According to Calculus 1 these results make perfect sense to me
  • 4
    @olback any number x dividing it self will give you 1.

    However, infinity is not a number it is a concept of infinitesimal calculus
  • 3
    Number of JavaScript Frameworks = infinity
  • 0
    @olback ifinity 🤔🤔
  • 1
    Why some of you are amazed by this? Who the fuck does this anyway? Every line of that can be easily and in an non confusing matter be explained. There's no spooky action at a distance, nothing. Just that jerks/elitists like to pick on javascript just because they have the superiority syndrome.
  • 1
    I know this behaviour cames from iee 754 but it's mathematical incorrect
  • 0
    @localghost why incorrect?
Add Comment