ans >= Math.log(a) / Math.log(b);
ans为整数,求ans
右侧强转int是错误的。
(2.0 -> 2, 2.6 -> 3, 3.0 -> 3)
方法已提供,使用 Math.ceil(),向上取整。
所以求 >= double类型 的整数时,使用Math.ceil(),记得该函数返回类型也为double。
对应的
ans <= Math.log(a) / Math.log(b);
ans为正数,求ans的话,其实是对右侧向下取整. 刚想了一下,和使用int强转也可实现,不知道对否。
(2.6 -> 2, 2.0 ->2, 3.0->3)