I’ve recently had a discussion with a colleague on whether it is a good practice using Math.pow() to square a number?
My friend’s argument is that Math.pow() is designed to raise a number to a partial power, such as 7^2.5. Therefore it will use complicated and inefficient math raising a number to 2.0 instead of more efficient way of simply x*x. He advocated implementing and using a square function below instead of using Math,pow( x, 2.0);
So the question remains:
A) public static double square( double x ){ return x * x; }
or
B) Math.pow( x, 2.0 );
?????
Please give us your input!
———————————————
pow
public static double pow(double a,
double b)
- Returns the value of the first argument raised to the power of the second argument. Special cases:
- If the second argument is positive or negative zero, then the result is 1.0.
- If the second argument is 1.0, then the result is the same as the first argument.
- If the second argument is NaN, then the result is NaN.
- If the first argument is NaN and the second argument is nonzero, then the result is NaN.
- If
- the absolute value of the first argument is greater than 1 and the second argument is positive infinity, or
- the absolute value of the first argument is less than 1 and the second argument is negative infinity,
then the result is positive infinity.
- If
- the absolute value of the first argument is greater than 1 and the second argument is negative infinity, or
- the absolute value of the first argument is less than 1 and the second argument is positive infinity,
then the result is positive zero.
- If the absolute value of the first argument equals 1 and the second argument is infinite, then the result is NaN.
- If
- the first argument is positive zero and the second argument is greater than zero, or
- the first argument is positive infinity and the second argument is less than zero,
then the result is positive zero.
- If
- the first argument is positive zero and the second argument is less than zero, or
- the first argument is positive infinity and the second argument is greater than zero,
then the result is positive infinity.
- If
- the first argument is negative zero and the second argument is greater than zero but not a finite odd integer, or
- the first argument is negative infinity and the second argument is less than zero but not a finite odd integer,
then the result is positive zero.
- If
- the first argument is negative zero and the second argument is a positive finite odd integer, or
- the first argument is negative infinity and the second argument is a negative finite odd integer,
then the result is negative zero.
- If
- the first argument is negative zero and the second argument is less than zero but not a finite odd integer, or
- the first argument is negative infinity and the second argument is greater than zero but not a finite odd integer,
then the result is positive infinity.
- If
- the first argument is negative zero and the second argument is a negative finite odd integer, or
- the first argument is negative infinity and the second argument is a positive finite odd integer,
then the result is negative infinity.
- If the first argument is finite and less than zero
- if the second argument is a finite even integer, the result is equal to the result of raising the absolute value of the first argument to the power of the second argument
- if the second argument is a finite odd integer, the result is equal to the negative of the result of raising the absolute value of the first argument to the power of the second argument
- if the second argument is finite and not an integer, then the result is NaN.
- If both arguments are integers, then the result is exactly equal to the mathematical result of raising the first argument to the power of the second argument if that result can in fact be represented exactly as a
doublevalue.
(In the foregoing descriptions, a floating-point value is considered to be an integer if and only if it is finite and a fixed point of the method
ceilor, equivalently, a fixed point of the methodfloor. A value is a fixed point of a one-argument method if and only if the result of applying the method to the value is equal to the value.)The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
-
- Parameters:
a– the base.b– the exponent.- Returns:
- the value
ab.
Many are not aware of the optimized logic statements. This could lead to the logic errors. In Java there are two AND and two OR statements. One is optimized and one is not. The optimized operator will not evaluate a second (right) statement if the final outcome is clear from evaluation of the first (left) statement.
When designing an application that is made up of Java and Native code it is important to handle signals correctly. What I’m trying to say is that JVM uses signals internally and if your application registers itself as a signal handler it will intercept signals intended for JVM. As a result JVM’s signal handler will not be invoked. Eventually this will lead to incorrect behavior and most likely a JVM crash.

As you already know, JTabbedPane provides a convenient way for components such as JPanels to share the same real estate on the screen.
I want to open this blog by discussing a few techniques of launching a java server and it’s side kick rmi-registry.