Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Meaning Of error in perl

by grewal7634 (Novice)
on Jul 08, 2014 at 06:08 UTC ( [id://1092678]=perlquestion: print w/replies, xml ) Need Help??

grewal7634 has asked for the wisdom of the Perl Monks concerning the following question:

What is the meaning of error in perl Illegal division by zero.

Replies are listed 'Best First'.
Re: Meaning Of error in perl
by davido (Cardinal) on Jul 08, 2014 at 06:13 UTC

    The division operation is undefined for divisors of exactly zero. Try it on your calculator.

    If that doesn't clear it up, Wikipedia ought to: Division by zero.

    Consider this unbreakable relationship:

    x = a / b a = b * x

    This relationship is fundamental to algebra; one expression cannot be decoupled from the other. So if x = a / 0, then x * 0 = a. If 'a' is non-zero, there is no value for 'x' that can produce a non-zero 'a' if 'b' is zero. Division by zero is undefined; it has no solution.


    Dave

Re: Meaning Of error in perl
by gurpreetsingh13 (Scribe) on Jul 08, 2014 at 07:16 UTC
    See this:
    Lets assume x = y
    That means 2x = 2y
    That means 2*(x-y) = 1*(x-y)
    Dividing by (x-y) both sides, we get 2 = 1
    So, that is wrong since x = y being x-y = 0. As such division by 0 is not acceptable in Mathmatics. You can call it Infinity.
    That is why that error.

      Lets assume x = y
      That means 2x = 2y
      That means 2*(x-y) = 1*(x-y)

      How did you go from line 2 to line 3, for ...

      x = y or, 2x = 2y or, 2x - 2y = 2y - 2y or, x - y = 0

      ... which was the origin with the assumption of x = y of course?

        x = y
        2x-x = 2y-y
        2x-2y = x-y
        2*(x-y) = 1*(x-y)
      Thanks
Re: Meaning Of error in perl
by thanos1983 (Parson) on Jul 08, 2014 at 12:45 UTC

    Hello grewal7634,

    It would be much easier to assist you by providing a working example of your code here. But since this is not available this is my explanation and best approach to solve your problem.

    As everybody answered already with examples your error comes from dividing a number with zero.

    The process can not be completed.

    I assume that in your calculation somewhere you have a syntax error and you divide a number with zero. I would suggest to insert print statements at every step of your calculation so you can detect where the error is coming from.

    Update,

    This is the first result that I found when I insert your error on Google What does the error 'Illegal division by zero' mean?. I think you will find more information there with some code that maybe assist you to understand what is the error or how to find your error.

    Hope this helps.

    Seeking for Perl wisdom...on the process...not there...yet!
Re: Meaning Of error in perl
by perlfan (Vicar) on Jul 08, 2014 at 14:20 UTC
    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.
      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].

Log In?
Username:
Password:

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

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

    No recent polls found