Hacker News new | ask | show | jobs
by archargelod 942 days ago
> The following design choices may be considered controversial by some:

> Dividing by zero yields zero. https://www.hillelwayne.com/post/divide-by-zero/

That's one interesting point I would love to read any opinions on.

Edit: Here's a HN discussion about the `divide by zero` article - https://news.ycombinator.com/item?id=17736046

3 comments

There's a brief description of the same choice[0] made by the Pony language.

[0] https://tutorial.ponylang.io/gotchas/divide-by-zero.html

FWIW, I tend to write a lot of error checking code that checks for division by zero ahead of time and just returns zero instead. Found an example:

        public double magnitude
        {
            get
            {
                double c = max_magnitude;
                return c > 0 ? Math.Max(c, c * (this / c)._internal_magnitude) : 0;
            }
        }
I could delete quite a few if statements in pretty hot codepaths if division by zero just returned zero.
This feels like an area where extended/vector instructions could be added to make this fast too. Probably not news to you, but for example, NEON (and likely AVX, I’m just a lot less familiar with it) has saturating addition and subtraction.
This is notable too:

In the year since I wrote this post, Pony added partial division. I still don’t know anything about the language but they’ve been getting grief over this post so I wanted to clear that up.

https://tutorial.ponylang.io/expressions/arithmetic.html#par...

I think Hillel's post was just saying that 1/0 == 0 doesn't lead to any mathematical contradictions.

Another way to think about it is that I believe 1/0 == 42 and 1/0 == 43 are just as valid. They don't lead to contradictions.

[In ZF set theory] Since 0 is not in the domain of recip, we know nothing about the value of 1 / 0; it might equal √2, it might equal R, or it might equal anything else.

But I don't think you want to use a language where 1/0 == 42, and likewise for 0.