I am looking into Math.pow() function in Java but the following code gives different results as shown below respectively.
Case 1:
BigDecimal divisor = new BigDecimal(Math.pow(10,9)+7);
BigDecimal dividend = new BigDecimal(1000000000543543509L);
System.out.println(dividend.remainder(divisor)); // 543543558
Case 2:
System.out.println((1000000000543543509L%((int)Math.pow(10,9)+7))+"");
//543543558
Case 3:
System.out.println((1000000000543543509L%(Math.pow(10,9)+7))+""); //5.43543601E8
Why do I get different results in Case 2 and 3 but same in Case 1 and 2? Which of the above cases is most accurate ?