Infinity Considered Harmful

Although we are an embedded shop, we occasionally need a quick (and dirty) utility for testing or simulation.

For reasons that are lost in history, VisualBasic was chosen for this. Further, with the introduction of DotNet, we seem to be adopting VbDotNet (VisualBasicDotNet) as the successor for our quick (and even dirtier) utilities.

Well, there are a variety of porting issues, which evoke howls of laughter (or is that cursing) among the embedded guys, who really just want to write/burn/test and don't want to have to also write/compile/test the damned simulator.

Yesterday, one of them pointed out that 100/0 is no longer "undefined" or "an exception" but is now "infinity."

Oh, gawd. Well, all you morons with a PHD in math will have to take a refresher course now. Clearly, MicrosoftMath? will be replacing real math, and you'll have to find a way to deal with this infinity thing.

-- GarryHamilton

Did you confirm that this is VB at work? I had a vague memory that the Pentium floating point unit had a mode to select the response to division by zero, and that yielding Inf was one of the possibilities. If so, then it might just have been left in the wrong mode, which is fixable.

Yup, it's evidently part of the DotNet CLR thing. I note that there is discussion below about whether and when "infinity" is a valid result from anything/0. Since I'm not a MathPhd?, could somebody clarify for me what conditions must exist for AnythingByZero? to have actual meaning? Thanks. -- gh

Actually there's Infinity, PositiveInfinity, NegativeInfinity and NaN in CTS floating-point implementation. -- Alexei Marine

Literally speaking, never, but figuratively it can be a shorthand for talking about a limit that approaches infinity as the dividend approaches zero. To be strictly correct, the shorthand should not be used, but admittedly that shorthand is handy sometimes, as long as it doesn't lead to confusion. Since programming tends to be about pragmatics, it's not necessarily harmful for software to do this, but I'd be doubly suspicious if there's no way to override that behavior.

(This is true even with new fangled non-standard analysis, btw.)

In non-standard analysis, 100 divided by an infinitesimal around zero will give you positive or negative infinity depending on whether the infinitesimal is positive or negative. None of that "approaches zero" shit however you can't apply the real() function to a hyperreal number until AFTER you've performed the division, because 100 divided by 0 is still undefined.

You mean will give you an infinity (positive or negative), or more precisely, an illimited number, which is larger than any finite number but still not equal to the traditional "infinity". And if you multiply that particular illimited number by the particular infinitesimal, you get 100 again, quite unlike if you were operating with infinity or zero.

[Hey, uhh, this "approaching zero" crap starts to sound a little like, um, calculus? Is that the intention here?]

"crap"? Which liberal arts college has given up on breadth requirements to the extent of allowing humanities majors to escape taking Calculus For Non-majors?


There are entirely valid contexts in which 100/0 is infinity, they just don't happen to include the real numbers. I've used symbolic manipulation programs that make the distinction between infinite and simply undefined, and been grateful for it. The arguments against using this in something like VB aren't mathematical, like the above suggests, only pragmatic.

Quite true; division by zero is formally undefined, but when we do arithmetic by computer we may be modeling any number of things other than the literal arithmetic itself, and there are in fact contexts when we are modeling approach to a limit, which may not be undefined. On the other hand, many consider this to be sloppy procedure.

I meant formal contexts. It's sloppy because they aren't usually the relevant ones.

But surely that's just an encoding issue. That is, you can write software that parses "x/0" as if it really had been spelled "infinity". I don't see offhand that there are any formal mathematical contexts where it is possible to literally define division by the additive identity of the ring. At most in a formal domain things can become defined that weren't in the original domain being modeled precisely because the mappings to "values" change, as with formal power series avoiding divergence issues.

It's possible in contexts where you're not concerned about the ring structure, but are concerned about the geometry. In the projective line (or Riemann sphere if you include complex numbers), 1/0 is infinity in a very formal sense, though infinity times zero is left undefined. Because these spaces are compact, they're a natural place to talk about limits.

I'm not actually disagreeing with you. I just think the above comment about MS math, and about how every real mathematician would leave division by zero undefined, is an unnecessary slur on many mathematicians and on the VB programmers. There are more than enough valid criticisms of the latter.

True. People tend to be kind of knee-jerk about such things, which sometimes is called for, but other times is overly nitpicky. Or is taking an easy shot.


I'm actually simultaneously pleased and dismayed to see that the concept is not as clear-cut as I originally thought. There is, however a small problem with the language simply absorbing AnythingByzero? and returning infinity: the accounting systems we support don't have a place for that, and we can't do meaningful percentage computations with it.

In our context, AnythingByZero? is actually an error -- it must not be allowed -- and if we somehow let a zero divisor through, we need to halt, not "try to make sense of it" and pass on the result. We must now police the inputs and outputs, not only for potential zero divisors, but now also for infinite results.

We're all looking forward to this small, tiny, insignificant, meaningless, trivial alteration of our system logic.

-- GarryHamilton

A little web searching reinforces my memory: it is possible to tell the Pentium whether to produce Inf or to raise an exception, and CLR is, I would think, likely to using the FP unit mode rather than implementing divide by zero as Inf in software. See http://www.panopticoncentral.net/articles/916.aspx

The problem with trying to fix that, though, is that operating systems typically are loath to change the FP mode on every context switch, because it's huge (512 bytes). And yet, if any given process changes the FP mode to something unsuitable for other processes, it could screw up all the other processes, unless the mode is indeed restored per context switch.

Unfortunate.

On the bright side, you can typically delay your checks for Inf until higher level modules, since they accumulate.

You know, there must be thousands/millions of other people worldwide facing your identical problem, suggesting that the least painful of the various solutions might already have been invented and available if you search forums and Usenet groups...


See: IeeeSevenFiftyFour (IEEE floating point standard)

For true rants: ThereIsNoInfinity

CategoryRant


EditText of this page (last edited October 30, 2004) or FindPage with title or text search