Wrong result by Java Math.pow

后端 未结 6 1846
挽巷
挽巷 2020-12-06 17:17

If you try to run the following code

public class Main {
   public static void main(String[] args) {
       long a = (long)Math.pow(13, 15);
       System.ou         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 17:37

    A double has finite precision, its mantissa is 52 bits, which roughly equals 15 to 16 decimals. So the number you're trying to calculate can't be represented (exactly) by a double any more.

提交回复
热议问题