+ 2
Infinity Question
This question comes from timed a JavaScript Challenge. The question is: What is the output of the code? let a = 1; let b = Infinity; let c = 0; let x = (a/b) == c; let y = (a/c) == b; const z = x == y; console.log(z); The output is true. Is this because 1/Infinity is 0 and 1/0 is also 0? Thank you for helping! ❤️
6 odpowiedzi
+ 6
1/Infinity is 0, so x contains `true`.
1/0 is Infinity, so y contains `true`.
The output is true because `true == true`!
+ 3
[definitely meta] Mostly to help you think about questions playing with Infinity (and why 1/0 and 1/-0 are different).
1/0 describes what you're approaching on the way to 0 from "above" (i.e., the positive side)
Visualization:
Place 1/x in a formula line here:
https://code.sololearn.com/WWE2g9B1nka6/?ref=app
Then follow the graph towards 0...as x approaches:
0 from the right, the graph blows up towards infinity (1/0.00000000001 is a very positive number)
-0 from the left, the graph plummets down towards -infinity (1/-0.000000001 is a very negative number)
In Javascript, approaching 0 from either side produces two different results:
1/Math.round(0.1) = Infinity // rounds to 0
1/Math.round(-0.1) = -Infinity // rounds to -0
Mostly just FYI but it may help explain why Infinity shows up there.
~ (Signed 0's are used for tracking state in some langs/maths)
+ 2
Ohhhh! 1/0 is Infinity.
Ok, thanks!
+ 1
Thanks, Schafer 😃 your calculator is mind blowing!
+ 1
Ah, I'm only linking into a public API because it has extra abilities like: extract the formulas / control it programmatically / creating my own webpages...
...but the majority of the code is Desmos'. The Android app is pretty good for the general use case :)
0
Kirk Schafer P.S. My last name is also "Shafer" but I just realized you have no way of knowing that.