[jira] Resolved: (MATH-154) MathUtils addAndCheck and subAndCheck for long values

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (MATH-154) MathUtils addAndCheck and subAndCheck for long values

JIRA jira@apache.org

     [ 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.