|Don't ask to ask, just ask|
After the discussion a few weeks back about zero and the quirks it introduces in mathematics, I realized there were some other mathematical points that could be brought up with respect to Perl and programming... and (hopefully) we won't need Math degrees to understand these. :-)
I forget exactly what I was doing to get to the point where I was doing something in Perl that used "0 ** 0" (it was probably another obfu...), but after I realized that the results didn't agree with what I thought they should be, I tried the expression (modified for the various platforms, of course) in a few different places:
My point is that I'm getting a consistent result of 1 with the computer languages I can try out... but from what I know of Mathematics, that just ain't right. And to make things more troubling for my psyche, I'm getting answers that support me from my calculators... and I've got two Microsoft products telling me different things. But that's no surprise.
For those who are wondering what the answer should be... well, until I played around with all this, I was pretty sure the answer was undefined. And I'm still pretty sure of that, but now I'm trying to figure out just how these operations are defined in the various languages to get these results.
So my question here is: What's going on?!? Is this another case of programming math gone wrong? And if all these languages are willing to choke on division by zero, why won't they choke on this? Speaking of that subject...
Division by zero
In addition, I have another point which fits in with this discussion of mathematical murkiness. In virtually (?) all programming languages, "x / 0" will result in some sort of Very Bad Thing happening. In C, the program will die. In Java, an ArithmeticException is thrown. In Perl, the script will also die unless you do something eval. (I'm sorry, that's a horrible pun -- please don't throw moldy cheese at me.)
My point here is that, given Perl's undef value, it sounds a lot nicer to say something like:
... than it is to do this:
So why can't dividing by zero result in an undefined value, as mathematics would have us believe? Division by zero would still result in a few warnings under -w if this undefined value was used later on, correct? I guess what I'm really saying is that I don't think that this should be the (near-)fatal problem that it is at the moment, as it really doesn't fit with (what I perceive as) Perl's "enough rope to hang yourself" idea...
... of course, that's just my opinion. It's likely quite incorrect. ;-) Your thoughts?
His Royal Cheeziness