commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ole Ersoy <>
Subject [Math] Precision.roundUnscaled BIG_DECIMAL
Date Sat, 12 Dec 2015 20:45:16 GMT

I'm creating a new utilities module and I'm trying to decide whether to keep the below code
block (Contained in the Precision.roundUnscaled() method - BTW it contains a new exception
type I'm playing with - see if interested
- the utilities module will be published soon putting the new exception code to validated
use ... hopefully - anyways here's the block):

         case BigDecimal.ROUND_UNNECESSARY:
             if (unscaled != FastMath.floor(unscaled)) {
                 throw new MathException(ExceptionTypes.MATH_ARITHMETIC_EXCEPTION);

So I would pass in the unscaled argument and say that rounding is not necessary.  Then if
the exception is thrown, I know that presumably I should have chosen one of the other BigDecimal
rounding operations...?

To me it seems simpler to check for the required operation like this before proceeding:

if (unscaled != FastMath.floor(unscaled)) {
// If necessary throw an application specific exception

Unless I'm missing something big, I'll remove the above code block, as well as the MATH_ARITHMETIC_EXCEPTION
in the firefly-math-utilities module....WDYT?

- Ole

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message