zorfael
asked on
Calculate Pow() and Log() without using java.math
Hi there,
I needed to do some mathematics in an exercice but I am not allowed to use the java.math class, I need to calculate the power Pow() and logarithm log() with a custom base, base 10 would work as well.
thank you so much!
I needed to do some mathematics in an exercice but I am not allowed to use the java.math class, I need to calculate the power Pow() and logarithm log() with a custom base, base 10 would work as well.
thank you so much!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your effort however the "Math" class can never be mentioned and Pow() should work with numbers like 0.53232333 for example and I can't pass a number like that as "int". the Log() function should be base 10 or custom base. In fact I need Pow() to calculate Exponential, Sin, Cosine, if you guys had those functions as well that would be great but with just the Pow() my numbers will come out good because they do if I use math.pow().
any other solutions?
thank you so much
any other solutions?
thank you so much
ASKER
actually I made it to work with double numbers using brunoguimaraes solution but I still need a logarithm function that would the same value as the function below but whithout using the Math class:
public double Log(double a, double base)
{
double x;
x = math.log10(a)/math.log(bas e)
}
any ideas?
return x;
}
public double Log(double a, double base)
{
double x;
x = math.log10(a)/math.log(bas
}
any ideas?
return x;
}
ASKER
CSecurity Pow() solution works just like brunoguimaraes's solution when updated to use double instead of int.
My first example was in Double base itself:
double pow(double a, double b)
double pow(double a, double b)
ASKER
sure, however you referenced "Math" on your code:
"Math.sqrt"
I can't use that but that's not the problem right now as I got that figured out,
I need to calculate the Logarithm in a custom base now, any ideas?
thank you!
"Math.sqrt"
I can't use that but that's not the problem right now as I got that figured out,
I need to calculate the Logarithm in a custom base now, any ideas?
thank you!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you all!
Open in new window