commons-dev mailing list archives

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

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 https://github.com/firefly-math/firefly-math-exceptions 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);
             }
             break;

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?

Cheers,
- Ole


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message