Results 1 to 3 of 3

Thread: Problem with math.h pow

  1. #1
    Join Date
    Nov 2008
    Posts
    1,192

    Problem with math.h pow

    I just noticed something problematic with the pow.

    Code:
    pow (10, 2)
    This returns 100. Normal

    Code:
    (Unsigned short) pow (10, 2)
    This returns 99.

    Can anyone explain why?

  2. #2
    Join Date
    May 2008
    Posts
    816

    Re: Problem with math.h pow

    Use static_cast Operator. It converts expression to the type of type-id based solely on the types present in the expression.

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Problem with math.h pow

    Code:
    # include <iostream> 
    # include <math.h> 
    
    template <typename Type> 
    void myfunc () 
    { 
          std:: cout <<static_cast <unsigned short> (pow (10, 2)) <<std:: endl; 
    
          for (unsigned short i = 0; i <3; i + +) 
              if (i == 2) 
                   std:: cout <<static_cast <Type> (pow (10, i)) <<std:: endl; 
    }
    
    int main () 
    { 
          Myfunc <unsigned short> (); 
    }
    It's really strange

Similar Threads

  1. Math Bug in Microsoft Excel
    By M.N.S in forum MS Office Support
    Replies: 6
    Last Post: 24-02-2012, 01:43 PM
  2. Need a tablet for graduate math and C++ students?
    By Purnanada in forum Portable Devices
    Replies: 5
    Last Post: 24-06-2011, 09:38 PM
  3. It's all math in StarCraft 2
    By Flavia in forum Video Games
    Replies: 5
    Last Post: 05-04-2011, 10:56 PM
  4. Java ME SDK 3.0 Math Class
    By Jona-thon in forum Software Development
    Replies: 5
    Last Post: 15-07-2010, 11:48 PM
  5. Java math question
    By Daren in forum Software Development
    Replies: 2
    Last Post: 02-09-2009, 06:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,854,981.98593 seconds with 16 queries