Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Meaning Of error in perl

by perlfan (Vicar)
on Jul 08, 2014 at 14:20 UTC ( [id://1092730]=note: print w/replies, xml ) Need Help??


in reply to Meaning Of error in perl

Division by zero is undefined in any programming language (not just Perl), therefore if you have code that could produce a divisor that is 0, then you'll want to guard against that in some way.

Replies are listed 'Best First'.
Re^2: Meaning Of error in perl
by Laurent_R (Canon) on Jul 08, 2014 at 18:59 UTC
    Division by zero is undefined in any programming language (not just Perl)

    Although this is perfectly true, the underlying truth is that division by zero is mathematically undefinable.

      That's not quite true, actually. Division by zero is impossible -- that is to say, zero does not have a multiplicative inverse -- in any field or indeed any ring, but general rings can have zero divisors (i.e., there may be a non-zero element a for which there exists a non-zero element b such that ab = 0).

      If n is a composite number, then the quotient ring Z/nZ (basically the same as the integers, but with addition and multiplication carried out mod n) is an easy and natural example. Suppose that n = p * q for some p and q; [p] and [q] are elements of this ring, but since we're multiplying mod n, we've got [p] * [q] = [n] = [0].

        Agreed, if we redefine multiplication and division to mean something else than their common meaning, and also have them operate on objects that are not the common numbers, then many strange things can happen. Just as redefining white as a special shade of black might lead to embarrassing paradoxes. Don"t get me wrong, I know that mathematicians commonly "overload" the basic operators to mean something else than the common sense operations, and they have good natural reasons to do so.

        But within the context we are really talking about, i.e. common arithmetic multiplication and division between natural, relative, rational, algebraic, transcendental, real or complex numbers, division by zero is mathematically impossible and even inconceivable. And the same goes for integers and floating-point numbers in CS.

        I made the point that a division by 0 is mathematically impossible (Ok, granted, within the framework of the previous paragraph), because I feel this is a much more general and profound statement than just saying that it is not possible with all known programming language, which could be construed to mean that existing languages all have this limitation. This is not a language limitation, this is something which has been proven to be mathematically impossible. In other words, a very bold statement that it not only so, but will forever be so.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1092730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-04-25 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found