How does this line of code do 'a' to the exponent of 'b'?
The above code is in the StrictMath class (It's the whole method). In the Java Math class is (also the full method):
With this code anyone is able to do:
and then the variable 'power' will be equal to 8.0. How?
I don't really know what a native method is so that could be the reason that I don't understand whatever it is that I'm missing. Because when I try:
With:
I get an error when it runs through the code using the method saying:
in MyWorld on line 81 I have:
public static native double pow(double a, double b);
public static double pow(double a, double b) { return StrictMath.pow(a, b); // default impl. delegates to StrictMath }
double power = Math.pow(2, 3);
/** * Write a description of class TestMath here. * * @author Yehuda (1/2 of Nosson1459 - greenfoot.org user name) * @version 2/28/2017 */ public final class TestMath { private TestMath() {} public static double pow(double a, double b) { return TestStrictMath.pow(a, b); // default impl. delegates to TestStrictMath } }
/** * Write a description of class TestStrictMath here. * * @author Yehuda (1/2 of Nosson1459 - greenfoot.org user name) * @version 2/28/2017 */ public final class TestStrictMath { private TestStrictMath() {} public static native double pow(double a, double b); }
java.lang.UnsatisfiedLinkError: TestStrictMath.pow(DD)D at TestStrictMath.pow(Native Method) at TestMath.pow(TestMath.java:12) at MyWorld.<init>(MyWorld.java:81) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at greenfoot.core.Simulation.newInstance(Simulation.java:617) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:425) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:502) at greenfoot.core.Simulation.maybePause(Simulation.java:305) at greenfoot.core.Simulation.runContent(Simulation.java:218) at greenfoot.core.Simulation.run(Simulation.java:211)
showText("" + TestMath.pow(2, 3), 50, 50);