Uploaded image for project: 'Commons Math'
  1. Commons Math
  2. MATH-154

MathUtils addAndCheck and subAndCheck for long values

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.2
    • Labels:
      None

      Description

      public static long addAndCheck(long x, long y) {
      BigInteger s = BigInteger.valueOf.add(BigInteger.valueOf;
      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.subtract(BigInteger.valueOf);
      if (s.bitLength() + 1 > Long.SIZE)

      { throw new ArithmeticException("overflow: add"); }

      return s.longValue();
      }

        Attachments

        1. MathUtils.diff
          4 kB
          Remi Arntzen
        2. MathUtils.diff
          4 kB
          Remi Arntzen

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              remi_arntzen Remi Arntzen
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: