- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Looks like it is defined, just not consistent - maybe it means +INF == -INF and (in the right circumstances) 1 == INF.
Apparently, 2+2 = 5 for large values of 2.
http://en.wikipedia.org/wiki/2_%2B_2_%3D_5#Self-evident_truth
I actually believed that akismet had gone away, but he doesn't like my link
Admin
I don;t think he actually knows whether the OP is either, he's just being himself
Admin
But doesn't undefined in this sense mean too many possible solutions rather than 'no solution' as it seems some are suggesting. We cannot decide on an answer, not because one doesn't exist, but because we don't really understand what the answer should be because it could be many things.
Admin
Actually, given that by definition we show two sets are the same "size" by constructing a bijection between them, everything you just listed is exactly the same "size". Though you did say "sum" so maybe your weren't talking about cardinality, but if you really meant "sum" then I don't know what you were talking about.
Admin
Admin
I guess we should be used to you feeling like you should respond to every postm though.
Admin
Admin
My guess is that some management type created a requirement for the ability to "Safely divide by zero" and this resultant set of B.S. is meant to appease that management individual.
Admin
The randomize loop in the flowchart doesn't seem consistent with the source code and the functionality.
The loop should go back to the beginning if $n==0 is TRUE, whereas the flowchart shows the loop going back to the beginning if it is FALSE.
Am I missing something here?
Admin
MY BRAIN
Admin
PHP Gods use the royal pronoun.
Captcha: damnum Exactly what I thought on reading this implementation.
Admin
Actually that depends on the function; if you really want to divide by zero you need to take the limit of the function as it approaches zero. Sometimes this results is INF or -INF, a value, or it will fail to converge, in which case it is undefined.
Admin
Yes, you have the correct answer by the correct reasoning. It is undefined (math cannot give you an answer) because "we don't really understand what the answer should be".
Part of the problem is as you suggest, there are an infinite number of solutions for x in the equation:
x*0 = 0
A few levels of abstraction up, we find out it's not that we can't pick a definition, but rather that no consistent definition can possibly exist.
The closest analogy I can make without getting into the mathematical details:
Bicycles and cars are both vehicles, but for bicycles "removing the gas cap" is an undefined operation. If you want to remove a gas cap, you either have to locate a car, or modify a bicycle so that it has a gas cap. However, after you rush off to tell your friends that you figured out how to remove the gas cap from a bicycle, they tell you that you've modified the bicycle, so it's no longer really a bicycle, so it doesn't count.
If the mathematical details interest you, A Book of Abstract Algebra is about $12 brand new and written in a very conversational style.
Admin
My understanding is that the reason why dividing by zero is "undefined" is because when you divide by zero you get results like 2+2=5 and 2=3.
It's like those old math puzzles that were popular years ago where they step by step "proved" 2=3. When you examine one of the steps, you'd invariably find one step that would involve dividing by zero.
Admin
...What.
Division by 0 can mean many different things, depending on the situation. I guess the PHP God's prodigious skillset didn't include a grasp of elementary calculus. :(
...One other question. Why does the string 'php' mean zero? Is this some strange convention I've never heard of? Is there some kind of standards body specifying what number 'php' is? Deas 'Python' mean 24? What about 'C Pound'?
Admin
[quote user="Pedantic, perhaps"][quote user="Math Math Math"][quote user="The Ancient Programmer"]But doesn't undefined in this sense mean too many possible solutions rather than 'no solution' as it seems some are suggesting. We cannot decide on an answer, not because one doesn't exist, but because we don't really understand what the answer should be because it could be many things. [/quote]
You are close, what it means in practice is that pure division isn't sufficient, you have an overflow condition and a loss of precision. What to do about that is problem dependent. For real numbers the square root of a negative number is undefined, yet maybe if it's a tiny negative number what you want is the sqr() to return zero in that case. Rounding errors, noise, and bad user input cause problems.
Admin
Well, the code is indeed well commented...
Admin
It's called Pluralismajestatis. Gods do that.
Admin
oh my god what is this i don't even
ARGH
... wow, this is the work of a genius!
Admin
And dividing the same number by a negative number with progressively smaller absolute value gives a progressively smaller negative number, until dividing by 0 yields negative infinity.
Since you can define 0 as the +0 or -0 infinitesimal with equal justification, by this reasoning x/0=INF and x/0=-INF.
(Which all assumes that x is positive, in any case.)
Admin
Its fake. Has to be.
Admin
Actually if the string contains a number then the string is not equals to 0 but is converted to said number according to some algorithm I have long forgotten
Admin
+ABS(!"php"/"php")
Admin
So to cover all bases just average the two.
i.e. lim(x->0) ((y/x)+(y/-x))/2
= 0
Admin
The only thing I could think of when reading this was "What the fuck??"
CAPTCHA: augue. augue, my eyes!
Admin
This was certainly a joke, and probably a dig at the manager. I can imagine a conversation.
Manager: I got a call from the client, they see a problem when they divide by 0. Can you do something about it? PHP God: But you shouldn't divide by 0 in the first place. Manager: I know, but the client insists on it. Please do something about it. PHP God: Fine, I will write some funky method which the client can use when they want to divide by 0. I will also show the code to the client so that they are convinced. Manager: Great, and make sure you put enough comments to explain what the new code does. PHP God: Fair enough. Give me 10 minutes.
Admin
UGH!!!!!
This has GOT to be one of, if not EVER the worst POS i have ever seen...
If you can't throw an exception, and handle it safely that way, at least, do the next most sane thing...
function SafeDivideByZero($a, $b) { return( $b == 0 ? INF : $a / $b ) ; )
... or possibly NAN, and check for this as a result, and handle it, or better yet.
However, the simplest and most obvious solution is - don't accept values to be divided with zero in the first place... It doesn't take a brain surgeon or rocket scientist to sort that..
Admin
Can't be, he looks too normal to be a programmer
Admin
Admin
Admin
Boooring. You can't just divide through by (x-1), because that's dividing by zero. Now, if you were trying to prove that 1 = "php", that's a different matter altogether...
Admin
I simply don't believe this is real code.
Surely nobody's that crazy.
Admin
TRWTF is people thinking there's such a mathematical operation as division. Poor things don't know enough multiplication.
Admin
Nope, the cardinality of all counting numbers is equal to the cardinality of all primes is equal to the cardinality of all integers which is equal to the cardinality of all rationals.
Look at it this way: the set of all integers >= 0 is the size as the set of all integers >0. You can pair 0 and 1, 1 and 2, 2 and 3, and so forth. There is always a number from the first to pair with the number from the second. No matter how big X you pick from the first set, there's always X+1.
And likewise, you can add negatives in. Your pairs are (1, 0), (2, -1), (3, 1), (4, -2), (5, 2) and so forth. Just as there's always X+1, there's also always 2X+1.
Conversely, the set of primes can't be smaller than the set of counting numbers. No matter how large a number I can imagine, by Euclid, I can always find a set of primes that is that large.
And for rationals, which are just integer / natural, imagine laying them out on a grid, X/Y. There will always be some integer X * Y that corresponds to X/Y.
So even though the rationals are "two-dimensional," there is still a 1 to 1 correspondence between them and the counting numbers. They are still "countably infinite."
You only lose that correspondence when you step up to real numbers; hard to explain and most of the explanations on the web are lousy.
Eh, it's a computer so I wouldn't read too much into it.
If I were writing a constraint based language, it could accept, e.g., x*x = 16, because it could try running other code with both x=4 and x=-4. It could even return two results.
But when dividing any x by 0, you approach both infinity and -infinity, you can't say it only equals (or approaches) one of them. So there's no solution that satisfies the equality. Not sure if this is any clearer.
It's been ages since I read that one...
Admin
FTFY
Admin
LOL! Even my 8-year-old nephew knows that dividing by zero technically gives you infinity.
Admin
TRFTFY
Admin
True, but only for sufficiently small values of "1".
Admin
I can deal with the implicit conversions and boolean tests.
But how would the denominator ever get set to the string "php" ?
Admin
Umm, I don't think that will work. I don't know PHP, but in most languages, dividing a sufficiently large number by minValue will result in an overflow.
Admin
Maybe this is the least of what's wrong with this code, but why in the world does he generate a random integer between 0 and 2, and if the result is zero loop around and generate another? Umm, wouldn't it be easier to just generate a random integer that is either 1 or 2? Or if he can't figure out how to generate random numbers that do not start from 0, just generate 0 or 1. All he's doing is checking for ==1 or !=1 anyway. 0 is just as not-equal to 1 as 2 is.
Well, maybe I should be careful about leaping to such a conclusion for PHP. If "php"==0 and 0==true and all that, maybe 1==0 sometimes returns true.
Admin
If (0 == "php") != ("php" == 0), that would be TRWTF.
Admin
Admin
We are talking about algebra not calculus
Admin
Which would throw an exception / crash the software, which is an appropriate response to an attempt to divide by zero!
Admin
Unless this in turn came from someplace else, this "PHP god" is not real, but instead is copy-pasted from a prankster on the Something Awful forums who posted this to make fun of another poster (note that the prankster has a period in his name while the target of his ridicule does not):
http://forums.somethingawful.com/showthread.php?threadid=3407474&pagenumber=20&perpage=40#post391261029
If you get a login error, an HTML copy of original page can be found here:
http://www.mediafire.com/?n1z8g2mx9bw324m
Admin
@frits:
trinity? :)
Admin
It's the royal we.
Admin
This feature would have been much, much easier to implement in BobX
Admin
It looks like the flow chart is incorrect. The decision, "is $n == 0 ?" is flipped. It should only go forward to "is $n == 1 ?" if it's False. :)