Thread: Problem with sqrt and cast

  1. #1
    Registered User
    Join Date
    Oct 2009

    Problem with sqrt and cast

    There is something I don't understand about casting. This works if I put a double in the place of (float)n.

    #include <math.h>
    int n = 10;
    printf("%f\n", sqrt((float)n));

  2. #2
    Registered User
    Join Date
    Sep 2004
    What's your question? double and float are both floating point types, the difference is that double has more precision.

    sqrt() takes a double type as the parameter. If you give it a int or a float, it will be implicitly converted to a double, so the cast is actually unnecessary.
    bit∙hub [bit-huhb] n. A source and destination for information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. use of static cast
    By alyeska in forum C++ Programming
    Replies: 3
    Last Post: 10-10-2007, 09:08 PM