Math.pow(100,0.10); Not giving expcted value

Math.pow(100,0.10) is not giving expected value, is there any other method to do such calculation? (expected = 10, 100^1/10=10 )

@shahid.dhariwala,
We will not actually use math.pow in this.

We will apply binary search in this problem. For every possible mid obtained by using binary search we will check of it is the best suitable candidate or not for becoming the Kth root and then we reduce the search space of the binary search according to the mid value.

If mid^k is greater than N then we will find the best suitable value from left to mid-1 otherwise we will find much larger value by finding it from mid+1 to right.

Thats fine but actually if i want to do such type of calculation 10^0.11 what should be my approach ? and possible solution ? is their any method ?

@shahid.dhariwala,

Example 1:

	int s = (int)Math.pow(100, 0.11);
	System.out.println(s);

This will give you output as 1.

Example 2:

	double s = Math.pow(100, 0.11);
	System.out.println(s);

This will give output as 1.6595869074375607

Math.pow takes in arguments in double and returns value in double as well.

	int s = (int)Math.pow(100, 0.10);
	System.out.println(s);
	1	
	double s1 = Math.pow(100, 0.10);
	System.out.println(s1);

            1.5848931924611136

But thats wrong 1/10th of 100 is 10 right

@shahid.dhariwala,

Power function works differently.

Like Math.pow(2,0.5) is 1.414…

We don’t calculate power like: 1/2th of 2 should be 1.

If 2^(0.5) is 1.4142135623730951 this means that if I do (1.4142135623730951) ^ 2 I will get 2.

Similar example:

25^(0.5) is 5. This means that if I do 5 ^ (0.5) is will get 25, which is true.

Similarly, if you do (1.5848931924611136)^10 you will get 100 (or near to 100).

Strange, but cool thank you for help :slight_smile: