I just noticed something problematic with the pow.
This returns 100. NormalCode:pow (10, 2)
This returns 99.Code:(Unsigned short) pow (10, 2)
Can anyone explain why?
I just noticed something problematic with the pow.
This returns 100. NormalCode:pow (10, 2)
This returns 99.Code:(Unsigned short) pow (10, 2)
Can anyone explain why?
Use static_cast Operator. It converts expression to the type of type-id based solely on the types present in the expression.
It's really strangeCode:# 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> (); }
Bookmarks