-1.#IND in output???

This is a discussion on -1.#IND in output??? within the C++ Programming forums, part of the General Programming Boards category; Hi, what does this output mean? Code: Discriminant = sqrtf(-16) or -1.#INDi Program code is as follows: Code: cout << ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91

    Question -1.#IND in output???

    Hi, what does this output mean?

    Code:
    Discriminant = sqrtf(-16) or -1.#INDi
    Program code is as follows:

    Code:
    cout << "Discriminant = sqrtf(" << discriminant << ") or ";
    	d1 = sqrtf(discriminant);
    	cout << d1 << "i" << endl << endl;
    Thanks a lot!

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    It means that the sqrt() of discriminant could not be calculated properly. The square root of negative numbers is not defined.

    Of course, you could always use
    Code:
    sqrt(fabs(discriminant))
    As for a more technical description of why it's "-1.#INDi" . . . I'm not entirely sure, but I'd guess that perhaps the trailing "i" means it's an imaginary number, which is what you get when you sqrt() a negative number. Google for more info.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    http://www.randelshofer.ch/fhw/gri/float.html
    #IND stands for indefinite.
    Other things you can get from time to time are #INF and #NAN.

    > I'm not entirely sure, but I'd guess that perhaps the trailing "i" means it's an imaginary number
    Nah, that's just the trailing i in the cout statement.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Jacksonville, AR
    Posts
    91
    Hi..

    Thanks dwks and Salem.. what you guys said made a lot of sense. It was the first time I have encountered that -1.#IND and now, at least I have an idea of what it stands for.

    Yes, the i came from the cout statement. However, I am trying to get the formula for the square root of the discriminant. Suppose, discriminant is equal to -16. Answer should be 4. How do I efficiently write the formula?

    Any ideas? I will experiment on the fabs function.

    Thanks guys..

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    However, I am trying to get the formula for the square root of the discriminant. Suppose, discriminant is equal to -16. Answer should be 4. How do I efficiently write the formula?
    Have you considered using the std::complex class template from <complex>? For example:
    Code:
    #include <iostream>
    #include <complex>
    
    template<typename T>
    void print(std::ostream& out, const std::complex<T>& x);
    
    int main()
    {
        std::complex<double> x(-16);
        std::cout << "sqrt(";
        print(std::cout, x);
        std::cout << ") = ";
        print(std::cout, sqrt(x));
        std::cout << std::endl;
    }
    
    template<typename T>
    void print(std::ostream& out, const std::complex<T>& x)
    {
        std::ios::fmtflags old_flags = out.flags();
        out << x.real() << std::showpos << x.imag() << "i";
        out.flags(old_flags);
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 02:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 02:29 PM
  3. Replies: 4
    Last Post: 11-30-2005, 03:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 04:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21