All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jose4j.lang.Maths Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 35.0.0.Beta1
Show newest version
package org.jose4j.lang;

public class Maths
{
    //Two's complement -> if the leftmost bit is 0, the number is positive. Otherwise, it's negative.

    public static long add(long x, long y)
    {
        long result = x + y;
        // if both arguments have the opposite sign of the result
        if (0 > ((x ^ result) & (y ^ result)))
        {
            throw new ArithmeticException("long overflow adding: " + x + " + " + y + " = " + result);
        }
        return result;
    }

    public static long subtract(long x, long y)
    {
        long result = x - y;
        // when arguments have different signs and sign of result is different than the sign of x
        if (0 > ((x ^ y) & (x ^ result)))
        {
            throw new ArithmeticException("long overflow subtracting: " + x + " - " + y + " = " + result);
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy