Returns the byte value that, when treated as unsigned, is nearest in value to value. @param value any long value @return (byte) 255 if value >= 255, (byte) 0 if value <= 0, and value cast to byte otherwise
(long value)
| 106 | |
| 107 | |
| 108 | public static byte saturatedCast(long value) { |
| 109 | if (value > toInt(MAX_VALUE)) { |
| 110 | return MAX_VALUE; // -1 |
| 111 | } |
| 112 | if (value < 0) { |
| 113 | return (byte) 0; |
| 114 | } |
| 115 | return (byte) value; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Compares the two specified {@code byte} values, treating them as unsigned values between 0 and |