- 4,663
- 36
Is there a predefined function in C++ that will allow me to take LOG(base 10) of a number? If not, is there a reasonably simple work-around?
thanks,
MIH
thanks,
MIH
The discussion revolves around the availability of predefined logarithmic functions in C++, specifically focusing on the base 10 logarithm. Participants explore the existence of such functions, potential workarounds, and related programming issues.
log10.log is available in the cmath header, with a note on using math.h for C-style headers.pow function, where the result is a double, and how to handle type casting to resolve an error with the modulus operator.static_cast to convert the result of pow to an integer for modulus operations.Participants generally agree on the existence of the log function and its declaration in the appropriate header. However, there is some uncertainty about the availability of a base 10 logarithm function and the correct usage of logarithmic functions in C++. The discussion includes multiple viewpoints on the best practices for handling logarithmic calculations and type casting.
Some participants mention difficulties in finding information in textbooks and documentation, indicating potential limitations in available resources or personal familiarity with C++. There is also a reference to varying experiences with different programming languages, which may affect participants' understanding of C++ functions.
This discussion may be useful for C++ programmers, particularly those interested in mathematical functions, type casting, and handling errors related to data types in programming.
sweet! thanks, gerben.gerben said:yes there is
pow() apparently returns a double, but you can change the type of the returned variable by type-casting it to an int like this:
num = num % static_cast<int>( pow(10, expo) );
Hurkyl said:Certainly. It's log. It's declared in the cmath header. (math.h if you're using C-style headers)
Math Is Hard said:ah well...who knows, franz. maybe you'll need that info one day.