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

MathUtils addAndCheck and subAndCheck for long values

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1
    • 1.2
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: