commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MATH-154) MathUtils addAndCheck and subAndCheck for long values
Date Sun, 06 Aug 2006 14:49:15 GMT
    [ http://issues.apache.org/jira/browse/MATH-154?page=comments#action_12426061 ] 
            
Phil Steitz commented on MATH-154:
----------------------------------

Looks like a good addition to MathUtils.

An alternative to the first implementations would be to convert to floats; but I suspect the
second versions will perform better, so I will commit this once we have:

a) test cases (see testAddAndCheck in o.a.c.math.util.MathUtilsTest for an example)
b) change the RuntimeExceptions to ArithmeticExceptions (as in first impl, consistent with
int versions)

Patches in diff format would be appreciated.

Thanks!

> MathUtils addAndCheck and subAndCheck for long values
> -----------------------------------------------------
>
>                 Key: MATH-154
>                 URL: http://issues.apache.org/jira/browse/MATH-154
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: Nightly Builds, 1.1 Final
>            Reporter: Remi Arntzen
>             Fix For: 1.2 Final
>
>
> public static long addAndCheck(long x, long y) {
>     BigInteger s = BigInteger.valueOf(x).add(BigInteger.valueOf(y);
>     if (s.bitLength() + 1 > Long.SIZE) {
>         throw new ArithmeticException("overflow: add");
>     }
>     return s.longValue();
> }
> public static long subAndCheck(long x, long y) {
>     BigInteger s = BigInteger.valueOf(x).subtract(BigInteger.valueOf(y));
>     if (s.bitLength() + 1 > Long.SIZE) {
>         throw new ArithmeticException("overflow: add");
>     }
>     return s.longValue();
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

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


Mime
View raw message