https://kotlinlang.org logo
#announcements
Title
# announcements
i

ishitatsuyuki

08/15/2017, 1:02 PM
Code: I'm doing a saturating
short
arithmetic.
Copy code
when {
                    a == 0.toShort() || b == 0.toShort() || (a > 0) xor (b > 0) -> a+b
                    x > 0 -> if (Short.MAX_VALUE - a < b) Short.MAX_VALUE else a + b
                    else -> if (Short.MIN_VALUE - a < b) Short.MIN_VALUE else a + b
                }.toShort()
b

benleggiero

08/15/2017, 1:07 PM
also
xor
is logically equivalent to
!=
2 Views