Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pow (x,y) in Java

Tags:

java

math

What's the difference between:

Math.pow ( x,y ); // x^y 

To:

x^y; // x^y 

?

Will I prefer to use x^y with double type numbers? Or shell I have to use always with Math.pow() method?

like image 241
Master C Avatar asked Apr 23 '11 10:04

Master C


People also ask

How do you find the X power of y in Java?

Java Program to Calculate Power of X to Y The function returns the power of x^y. Even though you can write this kind of function quickly, it's far from ideal, and if you really need a power function for your production code, I suggest you use the Math. pow() function because it's thoroughly tested.

What is pow () in Java?

pow() is used to calculate a number raise to the power of some other number. This function accepts two parameters and returns the value of first parameter raised to the second parameter. There are some special cases as listed below: If the second parameter is positive or negative zero then the result will be 1.0.

What is POW x N?

Write a function pow(x,n) that returns x in power n . Or, in other words, multiplies x by itself n times and returns the result. pow(3, 2) = 3 * 3 = 9 pow(3, 3) = 3 * 3 * 3 = 27 pow(1, 100) = 1 * 1 * ...


1 Answers

^ is the bitwise exclusive OR (XOR) operator in Java (and many other languages). It is not used for exponentiation. For that, you must use Math.pow.

like image 81
Michael Petrotta Avatar answered Sep 20 '22 22:09

Michael Petrotta