Live data from Hacker News

1.5 is the midpoint between 0 and infinity in Ruby

blog.peterzhu.ca

21–30 of 125 posts

Re: 1.5 is the midpoint between 0 and infinity in Ruby

#21

Meta: what is the time between the same URLs being considered unique posts on HN now? I think it was 24 hours back in the old days, but seems to be somewhat less now as the post's author submitted it only 9 hours ago: https://news.ycombinator.com/item?id=25224627 :-)

As I understand it, it depends on traction. That one got only 9 points; I don't know what the bar is, but I think resubmissions get another shot if it's not met.

(And if it's really soon after, submitting a duplicate just redirects you to the extant submission and upvotes it for you.)

Re: 1.5 is the midpoint between 0 and infinity in Ruby

#22
post #14

I vaguely remember learning similar fact years ago, but it was phrased something like "There are as many floats in [0, 1] range as in [1, infty]". Leaving aside where exactly "midpoint" of floats lies (either in Ruby's implementation or other languages'): what would be implications of this for writing code dealing with floats? Can I shoot myself in the foot somehow with low precision if numbers I'm using are "too clo…

What you describe is a common problem for video games, because if the engine uses "absolute" floats for everything in the game you effectively lose precision as you move away from the origin. If your maps get very large it gets very noticeable. I remember for instance in No Man's Sky when you traveled very far in a system you'd start to see the various animations become very jerky because the precision would become too low to represent the coordinates of the intermediary steps correctly.

See a random video showcasing the issue here: https://youtu.be/D2XX2ZnRk8M?t=197

You can see all the moving elements jerking around as they "snap" to the next available float value.

A common fix for this issue is to use two sets of coordinates: you can for instance represent your world as a grid with fixed-size cells, then you translate all your models into the local cell before computing anything, this way you always have good enough precision since you effectively limit the amplitude of your floats. Of course I handwave many complications here, such as what happens when you're at the edge of a cell for instance, but it's workable.

Re: 1.5 is the midpoint between 0 and infinity in Ruby

#25
That's because the well known fact that e^e = inf. Therefore log(inf) = e. Ruby is probably rounding up e/2.

Proof: the infinite series 1 + 1/2 +1/3! +... is known to converge to e. Now arrange in binomials: (1+1/2)^e + (1/3!)^e + ... this is known to be larger than (1+1/2)^2 + ... = 1 + 1/2 + 1/4 + 1 + 2/3 + 1/9 + ..... But this infinite series contains the series that sums to 2 (1 + 1/2 + 1/4 +...) and so the series that sums to 3, etc. Then it is equal to the sum of all positive integers which is infinite.

(This is a joke.)

Re: 1.5 is the midpoint between 0 and infinity in Ruby

#27

That's because the well known fact that e^e = inf. Therefore log(inf) = e. Ruby is probably rounding up e/2. Proof: the infinite series 1 + 1/2 +1/3! +... is known to converge to e. Now arrange in binomials: (1+1/2)^e + (1/3!)^e + ... this is known to be larger than (1+1/2)^2 + ... = 1 + 1/2 + 1/4 + 1 + 2/3 + 1/9 + ..... But this infinite series contains the series that sums to 2 (1 + 1/2 + 1/4 +...) and so the serie…

been looking at `e^e = inf` for a minute now and I just don't get the joke. What am I missing?

Re: 1.5 is the midpoint between 0 and infinity in Ruby

#28
Clearly we'll need to some work in TruffleRuby to be fully compatible. I really hope nobody's code depends on this.

  Infinity
  8.988465674311579e+307
  4.4942328371557893e+307
  2.2471164185778946e+307
  1.1235582092889473e+307
  5.6177910464447366e+306
  ...
  32767.999999999996
  16383.999999999998
  8191.999999999999
  4095.9999999999995
  2047.9999999999998
  1023.9999999999999
  511.99999999999994
  255.99999999999997
  127.99999999999999
  63.99999999999999
  31.999999999999996
  47.99999999999999
  39.99999999999999
  43.99999999999999
  41.99999999999999
  42.99999999999999
  42.49999999999999
  42.24999999999999
  42.12499999999999
  42.06249999999999
  42.03124999999999
  42.01562499999999
  42.00781249999999
  ...
  42.00000000000363
  42.00000000000181
  42.0000000000009
  42.00000000000045
  42.00000000000022
  42.00000000000011
  42.00000000000005
  42.00000000000002
  42.00000000000001
  42.0
  42.0
Post reply on HN