Class VectorMath
public final class VectorMath extends Object
VectorMath contains methods for performing scalar numeric operations in support of vector numeric operations.- Since:
- 24
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
static byte |
addSaturating |
Adds two byte values using saturation arithmetic. |
static int |
addSaturating |
Adds two int values using saturation arithmetic. |
static long |
addSaturating |
Adds two long values using saturation arithmetic. |
static short |
addSaturating |
Adds two short values using saturation arithmetic. |
static byte |
addSaturatingUnsigned |
Adds two byte values using saturation arithmetic and numerically treating the values as unsigned. |
static int |
addSaturatingUnsigned |
Adds two int values using saturation arithmetic and numerically treating the values as unsigned. |
static long |
addSaturatingUnsigned |
Adds two long values using saturation arithmetic and numerically treating the values as unsigned. |
static short |
addSaturatingUnsigned |
Adds two short values using saturation arithmetic and numerically treating the values as unsigned. |
static byte |
maxUnsigned |
Returns the greater of two byte values numerically treating the values as unsigned. |
static int |
maxUnsigned |
Returns the greater of two int values numerically treating the values as unsigned. |
static long |
maxUnsigned |
Returns the greater of two long values numerically treating the values as unsigned. |
static short |
maxUnsigned |
Returns the greater of two short values numerically treating the values as unsigned. |
static byte |
minUnsigned |
Returns the smaller of two byte values numerically treating the values as unsigned. |
static int |
minUnsigned |
Returns the smaller of two int values numerically treating the values as unsigned. |
static long |
minUnsigned |
Returns the smaller of two long values numerically treating the values as unsigned. |
static short |
minUnsigned |
Returns the smaller of two short values numerically treating the values as unsigned. |
static byte |
subSaturating |
Subtracts two byte values using saturation arithmetic. |
static int |
subSaturating |
Subtracts two int values using saturation arithmetic. |
static long |
subSaturating |
Subtracts two long values using saturation arithmetic. |
static short |
subSaturating |
Subtracts two short values using saturation arithmetic. |
static byte |
subSaturatingUnsigned |
Subtracts two byte values using saturation arithmetic and numerically treating the values as unsigned. |
static int |
subSaturatingUnsigned |
Subtracts two int values using saturation arithmetic and numerically treating the values as unsigned. |
static long |
subSaturatingUnsigned |
Subtracts two long values using saturation arithmetic and numerically treating the values as unsigned. |
static short |
subSaturatingUnsigned |
Subtracts two short values using saturation arithmetic and numerically treating the values as unsigned. |
Method Details
minUnsigned
public static long minUnsigned(long a, long b)
long values numerically treating the values as unsigned. That is, the result is the operand closer to the value of the expression 0L. If the operands have the same value, the result is that same value.- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the smaller of
aandb. - See Also:
maxUnsigned
public static long maxUnsigned(long a, long b)
long values numerically treating the values as unsigned. That is, the result is the operand closer to the value of the expression 0xFFFFFFFF_FFFFFFFFL numerically treating it as unsigned. If the operands have the same value, the result is that same value.- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the larger of
aandb. - See Also:
addSaturating
public static long addSaturating(long a, long b)
long values using saturation arithmetic. The lower and upper (inclusive) bounds are Long.MIN_VALUE and Long.MAX_VALUE, respectively. If the result of the addition would otherwise overflow from a positive value to a negative value then the result is clamped to the upper bound Long.MAX_VALUE. If the result of the addition would otherwise underflow from a negative value to a positive value then the result is clamped to lower bound Long.MIN_VALUE.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating addition of the operands.
- See Also:
subSaturating
public static long subSaturating(long a, long b)
long values using saturation arithmetic. The lower and upper (inclusive) bounds are Long.MIN_VALUE and Long.MAX_VALUE, respectively. If the result of the subtraction would otherwise overflow from a positive value to a negative value then the result is clamped to the upper bound Long.MAX_VALUE. If the result of the subtraction would otherwise underflow from a negative value to a positive value then the result is clamped to lower bound Long.MIN_VALUE.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating difference of the operands.
- See Also:
addSaturatingUnsigned
public static long addSaturatingUnsigned(long a, long b)
long values using saturation arithmetic and numerically treating the values as unsigned. The lower and upper (inclusive) bounds are 0L and 0xFFFFFFFF_FFFFFFFFL, respectively, numerically treating them as unsigned. If the result of the unsigned addition would otherwise overflow from the greater of the two operands to a lesser value then the result is clamped to the upper bound 0xFFFFFFFF_FFFFFFFFL.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating addition of the operands.
- See Also:
subSaturatingUnsigned
public static long subSaturatingUnsigned(long a, long b)
long values using saturation arithmetic and numerically treating the values as unsigned. The lower and upper (inclusive) bounds are 0L and 0xFFFFFFFF_FFFFFFFFL, respectively, numerically treating them as unsigned. If the result of the unsigned subtraction would otherwise underflow from the lesser of the two operands to a greater value then the result is clamped to the lower bound 0L.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating difference of the operands.
- See Also:
minUnsigned
public static int minUnsigned(int a, int b)
int values numerically treating the values as unsigned. That is, the result is the operand closer to the value of the expression 0. If the operands have the same value, the result is that same value.- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the smaller of
aandb. - See Also:
maxUnsigned
public static int maxUnsigned(int a, int b)
int values numerically treating the values as unsigned. That is, the result is the operand closer to the value of the expression 0xFFFFFFFF numerically treating it as unsigned. If the operands have the same value, the result is that same value.- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the larger of
aandb. - See Also:
addSaturating
public static int addSaturating(int a, int b)
int values using saturation arithmetic. The lower and upper (inclusive) bounds are Integer.MIN_VALUE and Integer.MAX_VALUE, respectively. If the result of the addition would otherwise overflow from a positive value to a negative value then the result is clamped to the upper bound Integer.MAX_VALUE. If the result of the addition would otherwise underflow from a negative value to a positive value then the result is clamped to lower bound Integer.MIN_VALUE.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating addition of the operands.
- See Also:
subSaturating
public static int subSaturating(int a, int b)
int values using saturation arithmetic. The lower and upper (inclusive) bounds are Integer.MIN_VALUE and Integer.MAX_VALUE, respectively. If the result of the subtraction would otherwise overflow from a positive value to a negative value then the result is clamped to the upper bound Integer.MAX_VALUE. If the result of the subtraction would otherwise underflow from a negative value to a positive value then the result is clamped to lower bound Integer.MIN_VALUE.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating difference of the operands.
- See Also:
addSaturatingUnsigned
public static int addSaturatingUnsigned(int a, int b)
int values using saturation arithmetic and numerically treating the values as unsigned. The lower and upper (inclusive) bounds are 0 and 0xFFFFFFFF, respectively, numerically treating them as unsigned. If the result of the unsigned addition would otherwise overflow from the greater of the two operands to a lesser value then the result is clamped to the upper bound 0xFFFFFFFF.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating addition of the operands.
- See Also:
subSaturatingUnsigned
public static int subSaturatingUnsigned(int a, int b)
int values using saturation arithmetic and numerically treating the values as unsigned. The lower and upper (inclusive) bounds are 0 and -0xFFFFFFFF, respectively, numerically treating them as unsigned. If the result of the unsigned subtraction would otherwise underflow from the lesser of the two operands to a greater value then the result is clamped to the lower bound 0.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating difference of the operands.
- See Also:
minUnsigned
public static short minUnsigned(short a, short b)
short values numerically treating the values as unsigned. That is, the result is the operand closer to the value of the expression 0. If the operands have the same value, the result is that same value.- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the smaller of
aandb. - See Also:
maxUnsigned
public static short maxUnsigned(short a, short b)
short values numerically treating the values as unsigned. That is, the result is the operand closer to the value of the expression 0xFFFF numerically treating it as unsigned. If the operands have the same value, the result is that same value.- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the larger of
aandb. - See Also:
addSaturating
public static short addSaturating(short a, short b)
short values using saturation arithmetic. The lower and upper (inclusive) bounds are Short.MIN_VALUE and Short.MAX_VALUE, respectively. If the result of the addition would otherwise overflow from a positive value to a negative value then the result is clamped to the upper bound Short.MAX_VALUE. If the result of the addition would otherwise underflow from a negative value to a positive value then the result is clamped to lower bound Short.MIN_VALUE.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating addition of the operands.
- See Also:
subSaturating
public static short subSaturating(short a, short b)
short values using saturation arithmetic. The lower and upper (inclusive) bounds are Short.MIN_VALUE and Short.MAX_VALUE, respectively. If the result of the subtraction would otherwise overflow from a positive value to a negative value then the result is clamped to the upper bound Short.MAX_VALUE. If the result of the subtraction would otherwise underflow from a negative value to a positive value then the result is clamped to lower bound Short.MIN_VALUE.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating difference of the operands.
- See Also:
addSaturatingUnsigned
public static short addSaturatingUnsigned(short a, short b)
short values using saturation arithmetic and numerically treating the values as unsigned. The lower and upper (inclusive) bounds are 0 and 0xFFFF, respectively, numerically treating them as unsigned. If the result of the unsigned addition would otherwise overflow from the greater of the two operands to a lesser value then the result is clamped to the upper bound 0xFFFF.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating addition of the operands.
- See Also:
subSaturatingUnsigned
public static short subSaturatingUnsigned(short a, short b)
short values using saturation arithmetic and numerically treating the values as unsigned. The lower and upper (inclusive) bounds are 0 and 0xFFFF, respectively, numerically treating them as unsigned. If the result of the unsigned subtraction would otherwise underflow from the lesser of the two operands to a greater value then the result is clamped to the lower bound 0.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating difference of the operands.
- See Also:
minUnsigned
public static byte minUnsigned(byte a, byte b)
byte values numerically treating the values as unsigned. That is, the result is the operand closer to the value of the expression 0. If the operands have the same value, the result is that same value.- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the smaller of
aandb. - See Also:
maxUnsigned
public static byte maxUnsigned(byte a, byte b)
byte values numerically treating the values as unsigned. That is, the result is the operand closer to the value of the expression 0xFF numerically treating it as unsigned. If the operands have the same value, the result is that same value.- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the larger of
aandb. - See Also:
addSaturating
public static byte addSaturating(byte a, byte b)
byte values using saturation arithmetic. The lower and upper (inclusive) bounds are Byte.MIN_VALUE and Byte.MAX_VALUE, respectively. If the result of the addition would otherwise overflow from a positive value to a negative value then the result is clamped to the upper bound Byte.MAX_VALUE. If the result of the addition would otherwise underflow from a negative value to a positive value then the result is clamped to lower bound Byte.MIN_VALUE.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating addition of the operands.
- See Also:
subSaturating
public static byte subSaturating(byte a, byte b)
byte values using saturation arithmetic. The lower and upper (inclusive) bounds are Byte.MIN_VALUE and Byte.MAX_VALUE, respectively. If the result of the subtraction would otherwise overflow from a positive value to a negative value then the result is clamped to the upper bound Byte.MAX_VALUE. If the result of the subtraction would otherwise underflow from a negative value to a positive value then the result is clamped to lower bound Byte.MIN_VALUE.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating difference of the operands.
- See Also:
addSaturatingUnsigned
public static byte addSaturatingUnsigned(byte a, byte b)
byte values using saturation arithmetic and numerically treating the values as unsigned. The lower and upper (inclusive) bounds are 0 and 0xFF, respectively, numerically treating them as unsigned. If the result of the unsigned addition would otherwise overflow from the greater of the two operands to a lesser value then the result is clamped to the upper bound 0xFF.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating addition of the operands.
- See Also:
subSaturatingUnsigned
public static byte subSaturatingUnsigned(byte a, byte b)
byte values using saturation arithmetic and numerically treating the values as unsigned. The lower and upper (inclusive) bounds are 0 and 0xFF, respectively, numerically treating them as unsigned. If the result of the unsigned subtraction would otherwise underflow from the lesser of the two operands to a greater value then the result is clamped to the lower bound 0.
- Parameters:
-
a- the first operand. -
b- the second operand. - Returns:
- the saturating difference of the operands.
- See Also:
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/jdk.incubator.vector/jdk/incubator/vector/VectorMath.html