package goja

// inspired by https://gist.github.com/orlp/3551590

var overflows = [64]int64{
	9223372036854775807, 9223372036854775807, 3037000499, 2097151,
	55108, 6208, 1448, 511,
	234, 127, 78, 52,
	38, 28, 22, 18,
	15, 13, 11, 9,
	8, 7, 7, 6,
	6, 5, 5, 5,
	4, 4, 4, 4,
	3, 3, 3, 3,
	3, 3, 3, 3,
	2, 2, 2, 2,
	2, 2, 2, 2,
	2, 2, 2, 2,
	2, 2, 2, 2,
	2, 2, 2, 2,
	2, 2, 2, 2,
}

var highestBitSet = [63]byte{
	0, 1, 2, 2, 3, 3, 3, 3,
	4, 4, 4, 4, 4, 4, 4, 4,
	5, 5, 5, 5, 5, 5, 5, 5,
	5, 5, 5, 5, 5, 5, 5, 5,
	6, 6, 6, 6, 6, 6, 6, 6,
	6, 6, 6, 6, 6, 6, 6, 6,
	6, 6, 6, 6, 6, 6, 6, 6,
	6, 6, 6, 6, 6, 6, 6,
}

func ipow(,  int64) ( int64) {
	if  >= 63 {
		if  == 1 {
			return 1
		}

		if  == -1 {
			return 1 - 2*(&1)
		}

		return 0
	}

	if  > overflows[] || - > overflows[] {
		return 0
	}

	 = 1

	switch highestBitSet[byte()] {
	case 6:
		if &1 != 0 {
			 *= 
		}
		 >>= 1
		 *= 
		fallthrough
	case 5:
		if &1 != 0 {
			 *= 
		}
		 >>= 1
		 *= 
		fallthrough
	case 4:
		if &1 != 0 {
			 *= 
		}
		 >>= 1
		 *= 
		fallthrough
	case 3:
		if &1 != 0 {
			 *= 
		}
		 >>= 1
		 *= 
		fallthrough
	case 2:
		if &1 != 0 {
			 *= 
		}
		 >>= 1
		 *= 
		fallthrough
	case 1:
		if &1 != 0 {
			 *= 
		}
		fallthrough
	default:
		return 
	}
}