Some people say "oh, that's easy, 1/0 is +Infinity". So the real fun is at 0/0. The limit of x/y as x and y go to zero depends on which path across the xy plane you take towards the singularity. Along one approach, the limit is 0, along another approach the limit diverges to infinity, along yet another the limit is 17. I'm not kidding! Go to https://www.geogebra.org/3d and enter "x/y" and spin the graph around. The "…
I would argue 1/0 is infinity. Not with mathematics, just logically. By using the wording "how many times does 0 go into 1?" You bring up 0/0. But 0/ is already defined, it's 0. So 0/infinity = 0 Programmatically, I think I've always wanted X/0 to be 0. For example: progress bars, currency, or damage in a video game. It wouldn't be very helpful to have infinity be an answer there.
1/0 = 0
201–210 of 593 posts
Re: 1/0 = 0
#202Earlier quoted context omitted.
> 2) this applies only to integer division wherein division by zero is undefined. 1.0/0.0 uses the available Infinity value. Oh jeeze... to me that almost nullifies all of the points in the article. It does an alright job explaining how 1/0 = 0 is at least consistent with other notions in the language, but to hear that the same logic can’t be applied to floats is just... well, objectively it’s a mess.
Here's another good one for you... What does your favorite programming language return for 3/2 as compared to 3.0/2.0? Many will return different values. EDIT: for clarity of my point: integer math that uses machine types is pretty surprising compared to what we would expect from "math" in general for division.
Re: 1/0 = 0
#203Oh, so 0*0=1 ?
If a hn title said 1*0=0 could you reply "Oh, so 1=0/0?" The entire point of the article was suggesting you can define a consistent system without multiplication and division being entirely symmetrical (as they already are not)
Re: 1/0 = 0
#204Another interesting example is array access. What should a[len(a)+1] be if your language doesn't have runtime errors?
Elm returns a Maybe type. However, this would be very awkward if you're actually doing a lot of calculations using arrays.
[Edit: Pony is different.]
Re: 1/0 = 0
#205Earlier quoted context omitted.
> 2) this applies only to integer division wherein division by zero is undefined. 1.0/0.0 uses the available Infinity value. Oh jeeze... to me that almost nullifies all of the points in the article. It does an alright job explaining how 1/0 = 0 is at least consistent with other notions in the language, but to hear that the same logic can’t be applied to floats is just... well, objectively it’s a mess.
Here's another good one for you... What does your favorite programming language return for 3/2 as compared to 3.0/2.0? Many will return different values. EDIT: for clarity of my point: integer math that uses machine types is pretty surprising compared to what we would expect from "math" in general for division.
just so long as you don't expect a consistent answer between python2.7 and 3.x... >.>
Re: 1/0 = 0
#206Earlier quoted context omitted.
Common compared to what? Taking an average of an empty array is nonsensical.
I disagree. It’s similar to computing NaN-mean or NaN-sum for an array of all NaN values (which returns 0). Let’s say some program calculates the mean of an array and then adds that mean to some accumulator. For purposes of updating the accumulator, the mean of an empty array is perfectly well-defined: it should add nothing to the accumulator (add 0). This might be a major operating requirement for the mean function,…
Why would you want to do this rather than validating understanding of the data before computing on this?
> For purposes of updating the accumulator, the mean of an empty array is perfectly well-defined: it should add nothing to the acculator (add 0).
That's not a mean, though, that's a quirk of how you decide to (incorrectly) compute a mean. What's the point of such a program? It should refuse to compute when it's given no values--that's clearly a category error.
Otherwise, you're not using a mean, you're using a mean-or-0-when-lacking-a-mean. Might as well not call it a mean at all so other people can read your code.
Yes, this is pedantic, but this kind of subtle changing meaning of terms is exactly what leads to bugs. Name your functions accurately.
Re: 1/0 = 0
#207Earlier quoted context omitted.
Here's another good one for you... What does your favorite programming language return for 3/2 as compared to 3.0/2.0? Many will return different values. EDIT: for clarity of my point: integer math that uses machine types is pretty surprising compared to what we would expect from "math" in general for division.
Did you mean 2/3?
Re: 1/0 = 0
#208My problem with "1/0 = 0" is that it's essentially masking what's almost always a bug in your program. If you have a program that's performing divide-by-zeroes, that's almost surely something you did not intend for. It's a corner case that you failed to anticipate and plan for. And because you didn't plan for it, whatever result you get for 1/0 is almost surely a result that you wouldn't want to have returned to the…
You're absolutely right. Not only that, but it's impossible to distinguish a bad result like 1/0 vs a good result like 0/1. Even Javascript is better with "NaN"
Re: 1/0 = 0
#209Edit: I guess there's a reason I'm not a language designer. I've always thought that programming languages should have a nonzero number class in the vein of unsigned and float and that division should only be defined with a nonzero number class as the denominator. To divide a 64-bit float by another float, you'd have to either specify it as nonzero in the type or convert it somehow. Make division by zero impossible w…
Re: 1/0 = 0
#210Earlier 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…