Live data from Hacker News

1.5 is the midpoint between 0 and infinity in Ruby

blog.peterzhu.ca

71–80 of 125 posts

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

#71
post #40

Earlier quoted context omitted.

Those clerics were ahead of their time. They probably would have banned large cardinals as well (infinites so large we can't prove whether or not they exist.)

I think a lot of cardinals around then were quite large, actually. https://www.alamy.com/portrait-of-cardinal-flavio-chigii-163... https://www.pinterest.com/pin/462252349233672807/

Even with the shortened URLs, I just knew this was going to be some reference to the Catholic church’s cardinals

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

#72
post #70

C++ :) #include #include double midpoint(double first, double second) { auto firstAsInt = reinterpret_cast (first); auto secondAsInt = reinterpret_cast (second); auto mid = (secondAsInt + firstAsInt) / 2; return reinterpret_cast (mid); } int main() { std::cout 1.5 = " inf = " ::infinity())

Rant:

Technically, that code invokes undefined behavior as you use `reinterpret_cast` to alias variables. The only standards conforming way (prior to `std::bit_cast`[0] in C++20) was to use `memcpy`.[a] `reinterpret_cast` was added for situations where code you have no control over requires a certain type, but you need to force it to take your variable.[b]

[a]: As `memcpy` (in addition to reinterpreting bits) copies the bits (although a compiler will most likely optimize it out), it doesn’t violate aliasing rules.

[b]: This also requires that the code you give your kludged variable to not read out those bits as what it thinks it is (because aliasing). Kindof pointless because: what’s the point of passing a variable that’s never read?

[0]: https://en.cppreference.com/w/cpp/numeric/bit_cast

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

#73
post #59

This all makes sense. It seems like there would be some special edge cases around the finite/NaN boundary that would be rarely exercised. I wonder if/how those are handled.

From Python: >>> import numpy as np >>> 1 + np.Inf inf >>> (0 + np.Inf)/2 inf >>> Infinity is not a number it is a concept[1] My math teacher used to say think of infinity like a impossibly large number. An impossibly large number divided by two is still an impossibly large number [1] http://mathforum.org/dr.math/faq/faq.large.numbers.html

While you’re correct, you’re being downvoted probably because you’re taking this seriously. I’m sure most everyone here knows infinity isn’t a number, but a concept, but you never know.

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

#74

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?

That \sum_{n=1}^inf 1/n is actually -1/12 /s

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

#75
post #59

This all makes sense. It seems like there would be some special edge cases around the finite/NaN boundary that would be rarely exercised. I wonder if/how those are handled.

From Python: >>> import numpy as np >>> 1 + np.Inf inf >>> (0 + np.Inf)/2 inf >>> Infinity is not a number it is a concept[1] My math teacher used to say think of infinity like a impossibly large number. An impossibly large number divided by two is still an impossibly large number [1] http://mathforum.org/dr.math/faq/faq.large.numbers.html

I'm not talking about math. I'm talking about computer numbers, specifically IEEE-754.

NaN is represented by a maximal (all ones) exponent, and at least one non-zero in the mantissa. Infinity has the same exponent but an all-zero mantissa. So with a naive comparison, NaN compares greater than infinity.

If you only believe output from programming languages, javascript claims that the type of infinity is "number".

    >>> typeof Number.POSITIVE_INFINITY
    "number"

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

#76
post #29

In surreal numbers [1], the midpoint between 0 and infinity would be the simplest number greater than 0, which is { 0 | } = 1 [1] https://en.wikipedia.org/wiki/Surreal_number

This is also consistent with the old joke that developers count like cavemen: zero, one, many!

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

#77
post #29

In surreal numbers [1], the midpoint between 0 and infinity would be the simplest number greater than 0, which is { 0 | } = 1 [1] https://en.wikipedia.org/wiki/Surreal_number

It's also the midpoint of the positive rationals, as modeled by the Stern-Brocot tree.

https://www.cut-the-knot.org/blue/Stern.shtml

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

#78

Earlier quoted context omitted.

I think a lot of cardinals around then were quite large, actually. https://www.alamy.com/portrait-of-cardinal-flavio-chigii-163... https://www.pinterest.com/pin/462252349233672807/

Even with the shortened URLs, I just knew this was going to be some reference to the Catholic church’s cardinals

thatsthejoke.jpg

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

#79
post #29

In surreal numbers [1], the midpoint between 0 and infinity would be the simplest number greater than 0, which is { 0 | } = 1 [1] https://en.wikipedia.org/wiki/Surreal_number

It's also the midpoint of the positive rationals, as modeled by the Stern-Brocot tree. https://www.cut-the-knot.org/blue/Stern.shtml

Exactly what I came to post. This is an important model for numbers.

Traditionally one distinguishes between rational, algebraic, and transcendental numbers; e is transcendental. This tree is related to continued fraction expansions. Any number is a limit of a path in this tree, and one can talk about the pattern in the path from a CS automata theory point of view. Now e comes out one of the easier limits.

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

#80
post #33

Earlier quoted context omitted.

> 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. Isn't this in practise creating a double-precision float by adding a second "significant figu…

Kind of but you get significantly better precision than if you just use a normal double float type because doubles only push the issues further out. Especially in games you're likely already breaking the world into cells for streaming chunks into/out of memory anyways.

Isn't this also just pushing the problem out? Once you get far enough out, you wouldn't be able to transition between cells because of the rounding error of the cell boundary being bigger than the cell size.

You can't represent infinite precision with finite bits so you must run into an issue eventually.

Post reply on HN