Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gokul.demo.InProgress;
- public class FastExpo {
- public static void main(String[] args) {
- FastExpo fe = new FastExpo();
- double myPow = fe.myPow(1.0000,-2147483648
- );
- System.out.println(myPow);
- }
- public double myPow(double x, int n) {
- if (n == 0) {
- return 1;
- }
- if (n < 0) {
- return 1 / myPow(x, -1 * n);
- }
- double k = myPow(x, n / 2);
- if (n % 2 == 0) {
- return k * k;
- }
- return k * k * x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement