Return Value MAX.round MAX

I use Math.round, and I find that it will not return me more than (2 ^ 32/2) -1, but the documentation says that it can / will return long values, i.e. 2 ^ 64 ... Below is a snippet of code.

long bTmp = (long)Math.round(4294967296L); System.out.println(bTmp); System.out.println(Long.MAX_VALUE); 

which outputs:

 2147483647 9223372036854775807 

Did I miss something?

+6
source share
1 answer

It calls the Math.round() overload, which takes a float and returns an int . See javadoc .

Try:

 Math.round((double) 4294967296L) 
+11
source

Source: https://habr.com/ru/post/912317/


All Articles