If you have any business logic which goes with computing 2 power n where n can be any integer identifying a partiuclar value, don't user Math.pow(2,n) method since it takes decimal number and the maximum value of "n" for which it can compute the results correctly is n=63 so if for any "n" value greater than 63 it will round the number and gives wrong results . To overcome this problem choose java.lang.BigDecimal object to compute powers.
From java 1.5 the BigDecimal class supports the pow() method which can compute correctly for any large numbers. It also comes with add() method which allows you to add large number correctly.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment