Live data from Hacker News

1/0 = 0

hillelwayne.com

211–220 of 593 posts

Re: 1/0 = 0

#211
post #97

So... if I do: x = a/b + c/d + e/(f*g/h) I need to check: if(b == 0 || d == 0 || f == 0 || g == 0) rather then: if(isFinite(x)) Or whatever function/equality check is appropriate, or a try/catch if it throws an exception. I have to say that using a single check on the result seems significantly less prone to bugs then having to check all the values that could produce an invalid result.

The problem being that constructing isFinite(..) for machine integer types is basically impossible.

Re: 1/0 = 0

#212
post #34

Earlier quoted context omitted.

I guess its more flipped. How many pieces equal the whole, not how many pieces can the whole be broken up into. That's why you can't divide by 0, any number of nothing can't make a whole. *disclamer: I have no math background whatso ever

The function "division" is just like any other function. It takes two inputs, and gives an output. The reason it's a useful function is it has some properties: y=1/x is continuous except where x==0. That is, as you approach 0 from either side, it grows to either +- infinity. The developers of this language want to make this function ==0 when x is 0. You can do that, sure, but it doesn't change the fact that when you…

ah thanks for the explanation!

Re: 1/0 = 0

#213
post #157

Earlier quoted context omitted.

We will be introducing two sets of integer math operators in Pony. The current which are non-partial and can over/underflow + division by zero == 0 AND new ones that will be partial functions that cause an error on under/overflow and division by zero.

> new ones that will be partial functions that cause an error on under/overflow and division by zero. A "strict" mode is usually always an afterthought once we have errors & people run it in strict mode and facepalm. One of the first "utilities" I wrote for PHP was something called "pecl/scream", which turned off all the "unchecked" operations across the whole VM. And in general, this works out poorly for code qualit…

There is no golden path here. Checked exceptions for division would make a lot of Pony code objectively worse. Unchecked exceptions are great for PHP, Haskell, Rust or Go, but Pony is trying to do something different - to literally make it impossible to panic in an operation without describing that in the type system. The ergonomics of divide by zero in this context are absolutely debatable, not an issue to dismiss out-of-hand.

Re: 1/0 = 0

#217
It is pretty annoying when you see NaN on a web page. I personally have fallen into the division by zero trap on numerous occasions.

Re: 1/0 = 0

#219

Hi, I'm on the Pony core team. I will be writing in more detail about this decision. A few short notes until then: 1) no one on the team has ever been happy with ending up here, understanding why the decision was made involved understand how partial functions (one that can produce errors like division by zero) are handled in Pony and interesting ergonomic issues that can result that is a large part of what my post wi…

Having 1/0 = 0 and 1.0f / 0.0f = +inf makes sense in two applications I can think of. The first would be currency systems in which prices down to the pre-determined fractional component are represented as unsigned integers. In calculating margin requirements division by zero equating to zero would be the correct answer. And two, for double precision continuous variables, any application involving 3D geometrical trans…

We are over in #ponylang on freenode if you ever want to stop by and chat.

Re: 1/0 = 0

#220

Earlier quoted context omitted.

I'm curious, what do you think about Julia's approach with its special "missing" value? Does this approach make sense outside the context of data analysis? https://julialang.org/blog/2018/06/missing

I can't really comment. I don't know how they are doing it and why they made that choice. I assume that Julia was already boxing integers in some fashion at which point this 100% makes sense to me. Also, given the performance profile that you are seeking to allow programmers to achieve, I think boxing all integers makes sense, then you can give folks protection from integer overflow and underflow and otherwise make h…

If I understand correctly, instead of the usual kind of boxing, they use a separate type tag (one byte) and support union types with up to 255 other "special" enum values. The type tags and data are stored separately, so instead of an array of boxed values, they internally have two arrays, one for type tags and the other for data.

Apparently this can work well with SIMD instructions.

Post reply on HN