Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Math.round MAX returnable value

Tags:

java

Am using Math.round and I am finding that it will not return me any value larger then (2^32/2)-1, but the documentation states it can/will return long values, i.e. 2^64... There a code snippet below.

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

which output:

2147483647
9223372036854775807

Am I missing something?

like image 285
cubearth Avatar asked Apr 03 '12 12:04

cubearth


1 Answers

It is calling the overload of Math.round() which takes a float and returns an int. See the javadoc.

Try:

Math.round((double) 4294967296L)
like image 52
Simon Nickerson Avatar answered Nov 08 '22 08:11

Simon Nickerson