2266 /** |
2266 /** |
2267 * Rounding mode to round away from zero. Always increments the |
2267 * Rounding mode to round away from zero. Always increments the |
2268 * digit prior to a nonzero discarded fraction. Note that this rounding |
2268 * digit prior to a nonzero discarded fraction. Note that this rounding |
2269 * mode never decreases the magnitude of the calculated value. |
2269 * mode never decreases the magnitude of the calculated value. |
2270 */ |
2270 */ |
2271 public final static int ROUND_UP = 0; |
2271 public static final int ROUND_UP = 0; |
2272 |
2272 |
2273 /** |
2273 /** |
2274 * Rounding mode to round towards zero. Never increments the digit |
2274 * Rounding mode to round towards zero. Never increments the digit |
2275 * prior to a discarded fraction (i.e., truncates). Note that this |
2275 * prior to a discarded fraction (i.e., truncates). Note that this |
2276 * rounding mode never increases the magnitude of the calculated value. |
2276 * rounding mode never increases the magnitude of the calculated value. |
2277 */ |
2277 */ |
2278 public final static int ROUND_DOWN = 1; |
2278 public static final int ROUND_DOWN = 1; |
2279 |
2279 |
2280 /** |
2280 /** |
2281 * Rounding mode to round towards positive infinity. If the |
2281 * Rounding mode to round towards positive infinity. If the |
2282 * {@code BigDecimal} is positive, behaves as for |
2282 * {@code BigDecimal} is positive, behaves as for |
2283 * {@code ROUND_UP}; if negative, behaves as for |
2283 * {@code ROUND_UP}; if negative, behaves as for |
2284 * {@code ROUND_DOWN}. Note that this rounding mode never |
2284 * {@code ROUND_DOWN}. Note that this rounding mode never |
2285 * decreases the calculated value. |
2285 * decreases the calculated value. |
2286 */ |
2286 */ |
2287 public final static int ROUND_CEILING = 2; |
2287 public static final int ROUND_CEILING = 2; |
2288 |
2288 |
2289 /** |
2289 /** |
2290 * Rounding mode to round towards negative infinity. If the |
2290 * Rounding mode to round towards negative infinity. If the |
2291 * {@code BigDecimal} is positive, behave as for |
2291 * {@code BigDecimal} is positive, behave as for |
2292 * {@code ROUND_DOWN}; if negative, behave as for |
2292 * {@code ROUND_DOWN}; if negative, behave as for |
2293 * {@code ROUND_UP}. Note that this rounding mode never |
2293 * {@code ROUND_UP}. Note that this rounding mode never |
2294 * increases the calculated value. |
2294 * increases the calculated value. |
2295 */ |
2295 */ |
2296 public final static int ROUND_FLOOR = 3; |
2296 public static final int ROUND_FLOOR = 3; |
2297 |
2297 |
2298 /** |
2298 /** |
2299 * Rounding mode to round towards {@literal "nearest neighbor"} |
2299 * Rounding mode to round towards {@literal "nearest neighbor"} |
2300 * unless both neighbors are equidistant, in which case round up. |
2300 * unless both neighbors are equidistant, in which case round up. |
2301 * Behaves as for {@code ROUND_UP} if the discarded fraction is |
2301 * Behaves as for {@code ROUND_UP} if the discarded fraction is |
2302 * ≥ 0.5; otherwise, behaves as for {@code ROUND_DOWN}. Note |
2302 * ≥ 0.5; otherwise, behaves as for {@code ROUND_DOWN}. Note |
2303 * that this is the rounding mode that most of us were taught in |
2303 * that this is the rounding mode that most of us were taught in |
2304 * grade school. |
2304 * grade school. |
2305 */ |
2305 */ |
2306 public final static int ROUND_HALF_UP = 4; |
2306 public static final int ROUND_HALF_UP = 4; |
2307 |
2307 |
2308 /** |
2308 /** |
2309 * Rounding mode to round towards {@literal "nearest neighbor"} |
2309 * Rounding mode to round towards {@literal "nearest neighbor"} |
2310 * unless both neighbors are equidistant, in which case round |
2310 * unless both neighbors are equidistant, in which case round |
2311 * down. Behaves as for {@code ROUND_UP} if the discarded |
2311 * down. Behaves as for {@code ROUND_UP} if the discarded |
2312 * fraction is {@literal >} 0.5; otherwise, behaves as for |
2312 * fraction is {@literal >} 0.5; otherwise, behaves as for |
2313 * {@code ROUND_DOWN}. |
2313 * {@code ROUND_DOWN}. |
2314 */ |
2314 */ |
2315 public final static int ROUND_HALF_DOWN = 5; |
2315 public static final int ROUND_HALF_DOWN = 5; |
2316 |
2316 |
2317 /** |
2317 /** |
2318 * Rounding mode to round towards the {@literal "nearest neighbor"} |
2318 * Rounding mode to round towards the {@literal "nearest neighbor"} |
2319 * unless both neighbors are equidistant, in which case, round |
2319 * unless both neighbors are equidistant, in which case, round |
2320 * towards the even neighbor. Behaves as for |
2320 * towards the even neighbor. Behaves as for |
2322 * discarded fraction is odd; behaves as for |
2322 * discarded fraction is odd; behaves as for |
2323 * {@code ROUND_HALF_DOWN} if it's even. Note that this is the |
2323 * {@code ROUND_HALF_DOWN} if it's even. Note that this is the |
2324 * rounding mode that minimizes cumulative error when applied |
2324 * rounding mode that minimizes cumulative error when applied |
2325 * repeatedly over a sequence of calculations. |
2325 * repeatedly over a sequence of calculations. |
2326 */ |
2326 */ |
2327 public final static int ROUND_HALF_EVEN = 6; |
2327 public static final int ROUND_HALF_EVEN = 6; |
2328 |
2328 |
2329 /** |
2329 /** |
2330 * Rounding mode to assert that the requested operation has an exact |
2330 * Rounding mode to assert that the requested operation has an exact |
2331 * result, hence no rounding is necessary. If this rounding mode is |
2331 * result, hence no rounding is necessary. If this rounding mode is |
2332 * specified on an operation that yields an inexact result, an |
2332 * specified on an operation that yields an inexact result, an |
2333 * {@code ArithmeticException} is thrown. |
2333 * {@code ArithmeticException} is thrown. |
2334 */ |
2334 */ |
2335 public final static int ROUND_UNNECESSARY = 7; |
2335 public static final int ROUND_UNNECESSARY = 7; |
2336 |
2336 |
2337 |
2337 |
2338 // Scaling/Rounding Operations |
2338 // Scaling/Rounding Operations |
2339 |
2339 |
2340 /** |
2340 /** |
3396 cmpCharArray[--charPos] = DIGIT_TENS[i2]; |
3396 cmpCharArray[--charPos] = DIGIT_TENS[i2]; |
3397 |
3397 |
3398 return charPos; |
3398 return charPos; |
3399 } |
3399 } |
3400 |
3400 |
3401 final static char[] DIGIT_TENS = { |
3401 static final char[] DIGIT_TENS = { |
3402 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
3402 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
3403 '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', |
3403 '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', |
3404 '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', |
3404 '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', |
3405 '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', |
3405 '3', '3', '3', '3', '3', '3', '3', '3', '3', '3', |
3406 '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', |
3406 '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', |
3409 '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', |
3409 '7', '7', '7', '7', '7', '7', '7', '7', '7', '7', |
3410 '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', |
3410 '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', |
3411 '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', |
3411 '9', '9', '9', '9', '9', '9', '9', '9', '9', '9', |
3412 }; |
3412 }; |
3413 |
3413 |
3414 final static char[] DIGIT_ONES = { |
3414 static final char[] DIGIT_ONES = { |
3415 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3415 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3416 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3416 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3417 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3417 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3418 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3418 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3419 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
3419 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |