I was testing boundary conditions on some code involving a BigDecimal, and I noticed that when a BigDecimal is initialized with the String "1e2147483647" it behaves unexpectedly. It seems to have a value between 0 and 1e-2147483647. When I try calling intValue(), I get a NegativeArraySizeException. I should note that 2147483647 is the max value of an integer on my system. Am I doing something wrong, or is this a problem with BigDecimal?
BigDecimal test = new BigDecimal("1e2147483647");
test.compareTo(new BigDecimal(0)); //Returns 1
test.compareTo(new BigDecimal("1e-2147483647")); //Returns -1
test.intValue(); //Throws NegativeArraySizeException
1e-2147483647is a pretty large number. To be precise,log_2(10^2147483647) / 8 / 1024^3 = 0.83...should yield the minimal size (in Gigabytes) to represent such a large number as integer. Maybe this is some kind of memory allocatin problem?BigDecimal. Your bug is legit.