commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brent Worden (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (MATH-154) MathUtils addAndCheck and subAndCheck for long values
Date Wed, 31 Oct 2007 07:22:50 GMT

     [ https://issues.apache.org/jira/browse/MATH-154?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Brent Worden resolved MATH-154.
-------------------------------

    Resolution: Fixed

Added addAndCheck, mulAndCheck, and subAndCheck MathUtils methods for long integer arguments.


> MathUtils addAndCheck and subAndCheck for long values
> -----------------------------------------------------
>
>                 Key: MATH-154
>                 URL: https://issues.apache.org/jira/browse/MATH-154
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 1.1, Nightly Builds
>            Reporter: Remi Arntzen
>             Fix For: 1.2
>
>         Attachments: MathUtils.diff, MathUtils.diff
>
>
> 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.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message