Thread: Division Result

  1. #1
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278

    Division Result

    What would be the result of the following divisions?

    Code:
    a. 1/0
    b. 1/INFINITY
    c. INFINITY/0
    d. 0/INFINITY
    e. INFINITY/1
    f. INFINITY/INFINITY
    g. 0/0

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Negative infinity - 42. Obviously.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
    #include <stdio.h>
    #include <math.h>
    int main(void) {
        float a = 1.0f;
        float b = 0.0f;
        float c = INFINITY;
        printf("%f %f %f %f %f %f %f\n", a/b, a/c, c/b, b/c, c/a, c/c, b/b);
        return 0;
    }
    C99 at least is guaranteed to follow IEEE guidelines.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Are you asking with respect to the rules of some branch of mathematics or a programming language?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    a. undefined
    b. nearly zero
    c. undefined
    d. zero
    e. infinity
    f. 1
    g.undefined (I think)
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by psychopath View Post
    a. undefined
    b. nearly zero
    c. undefined
    d. zero
    e. infinity
    f. 1
    g.undefined (I think)
    I'll give you 3.5/7 for that (at least as far as real analysis goes).

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Trying to remember from calc 2 (it has been awhile and was probably the least useful semester) but isn't the division by inf indeterminate? IIRC you can talk about a variable as it approaches infinity but you can't use infinity as a number.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    Are you asking with respect to the rules of some branch of mathematics or a programming language?
    This would be a critical question to get an answer to, as there is sometimes a significant difference between theoretical math and how a computer performs under those circumstances. Although I'm sure that both normally treat x/0 as "division by zero", where this normally leads to a hardware exception in a computer [so it stops the application] (but this is also usually configurable).

    As so often is the case, the question is not clear enough in it's scope to give a complete answer.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    Quote Originally Posted by Thantos
    IIRC you can talk about a variable as it approaches infinity but you can't use infinity as a number.
    In B I believe you would have to say that limit is zero as infinity is approached. But in D I was under the impression that whether you can treat infinity as a number or not, zero divided by anything had to be zero. And in F, anything divided by itself was always one.

    I could be completely wrong though. Only one year of precalc under my belt .
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, for f, consider (x^2)/x. Both go to infinity as x gets large, but the quotient is still infinity. (And of course, you can go the other way to get a quotient of zero, which is why f is undefined.)

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I don't think f is undefined but is indeterminate. I gotta dig out the book I think

  12. #12
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    And really since all but two are talking about infinity I have to assume that really means that as the function approaches some value it goes towards infinity. With the 0 it really depends if you mean:

    x / 0
    or
    x/f(y) as y approaches some number that causes f(y) to approach 0.

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Thantos View Post
    I don't think f is undefined but is indeterminate. I gotta dig out the book I think
    Same thing (or at least I meant by undefined what you mean by indeterminate).

  14. #14
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    I always thought that infinity is not a number, but a process, so an expression like 1/infinity is invalid and meaningless. You can express it as a limit, however, as in "(lim x->inf) 1/x". In that case, it's asking what value does 1/x approach as x approaches infinity. The answer would be 0.

    Anything divided by zero is undefined. "(lim x->0+) 1/x", though, is +inf, whereas "(lim x->0-) 1/x", is -inf.

    I have only taken one calculus course, though (AP calculus. graduating highschool this year ), so correct me if I'm wrong.

  15. #15
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by cyberfish View Post
    Anything divided by zero is undefined. "(lim x->0+) 1/x", though, is +inf, whereas "(lim x->0-) 1/x", is -inf.
    You can't have your cake and eat it too. What you say is not true when limits come into the picture. For example, the limit as x->0 of (x/x) is 1. Many basic results of differential calculus are based on such limits being defined.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Need help with basic calculation program.
    By StateofMind in forum C Programming
    Replies: 18
    Last Post: 03-06-2009, 01:44 AM
  3. Promblem with code
    By watchdogger in forum C Programming
    Replies: 18
    Last Post: 01-31-2009, 06:36 PM
  4. forcing division with int result
    By got1sleeve in forum C++ Programming
    Replies: 14
    Last Post: 01-16-2008, 04:37 AM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM