Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't there Math.Pow that takes an int as the exponent?

I read that the Math.Pow implementation is pretty complicated to be able to handle fractional powers. Why isn't there a version that takes an int for the exponent to make a faster version when you don't need fractional powers?

like image 204
Joan Venge Avatar asked Aug 02 '11 21:08

Joan Venge


People also ask

Can Pow be used with an INT?

Working of the pow() Function With Integers in C++ In C++, the pow() function is responsible for taking 'double' as the arguments of the program and returns a 'double' value as the output of the program. This function does not continuously work for integers.

Does Math POW return a double or int?

The method calculates multiplication of the base with itself exponent times and returns the result of type double .

Is Math POW inefficient?

Math. pow is slow because it deals with an equation in the generic sense, using fractional powers to raise it to the given power. It's the lookup it has to go through when computing that takes more time. Simply multiplying numbers together is often faster, since native calls in Java are much more efficient.

How do you raise an int to a power in C#?

Pow() Method. In C#, Math. Pow() is a Math class method. This method is used to calculate a number raise to the power of some other number.


1 Answers

Because you'd just need to convert it back into a float to multiply it against the logarithm of the base.

nm = em × ln n

like image 94
Ignacio Vazquez-Abrams Avatar answered Nov 15 '22 17:11

Ignacio Vazquez-Abrams