public class SafeMath extends Object
| Modifier and Type | Method and Description |
|---|---|
static int |
avg(int value1,
int value2)
Computes the average of two values without overflow or underflow.
|
static byte |
castByte(int value)
Casts int to byte, looking for any underflow or overflow.
|
static byte |
castByte(long value)
Casts long to byte, looking for any underflow or overflow.
|
static int |
castInt(long value)
Casts long to int, looking for any underflow or overflow.
|
static short |
castShort(int value)
Casts int to short, looking for any underflow or overflow.
|
static long |
multiply(long value1,
long value2)
Multiplies two longs, looking for any overflow.
|
public static byte castByte(int value)
throws ArithmeticException
ArithmeticException - for underflow or overflowpublic static byte castByte(long value)
throws ArithmeticException
ArithmeticException - for underflow or overflowpublic static short castShort(int value)
throws ArithmeticException
ArithmeticException - for underflow or overflowpublic static int castInt(long value)
throws ArithmeticException
ArithmeticException - for underflow or overflowpublic static long multiply(long value1,
long value2)
ArithmeticException - for overflowpublic static int avg(int value1,
int value2)
Copyright © 2016. All rights reserved.