I am trying to build an exponentiation function for real numbers where I cannot use the Math library in Java. The only operators I am allowed to use are +, -, * and /. No sqrt or log or any other function other than these 4 operators. I am able to do it for a whole number since it is pretty easy but cannot figure out how to for real numbers... Both the base and exponent can be real numbers
public static void power(){
System.out.println("\nPower function... ");
System.out.println("Enter the base: ");
long base = scan.nextLong();
System.out.println("Enter the exponent: ");
long exp = scan.nextLong();
System.out.println("Calculating " + base + "^" + exp + "...");
long answer = 1;
while(exp != 0) {
answer *= base;
exp--;
}
System.out.println(answer);
}