View Full Version : [SOLVED] forced float
chris200x9
February 18th, 2008, 03:24 AM
hi I can't figure out what's wrong with this forced float statement
digit = (num/ pow( float base, numDigits - num);
stroyan
February 18th, 2008, 05:11 AM
You didn't say much in your question about your situation.
For example, you didn't mention what language you are coding in. ;-)
I presume you are still coding in C++ as in your previous posts.
And I presume the variables you are using are of type int, resulting in an error like-
call of overloaded ‘pow(int&, int)’ is ambiguous
You need to put the type that you are casting to in parentheses, like
digit = (num/ pow( (float) base, numDigits - num);
aks44
February 18th, 2008, 08:07 AM
I presume you are still coding in C++ as in your previous posts.
[...]
You need to put the type that you are casting to in parentheses, like
digit = (num/ pow( (float) base, numDigits - num);
Funnily enough, you assume that the OP uses C++ but advise to use C casts. :-s
In C++, such a cast is done using static_cast<float>(base). Contrary to unchecked old-style C casts, new-style C++ casts are much safer, better take a good habit as early as possible.
As a side note, doubles are most of the time preferred over floats, there is no performance overhead but the precision is greatly enhanced.
popch
February 18th, 2008, 08:40 AM
hi I can't figure out what's wrong with this forced float statement
digit = (num/ pow( float base, numDigits - num);
The number of left parentheses does not match the number of right ones, to start with.
chris200x9
February 19th, 2008, 02:00 AM
thanks!
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.