unaryMinus
Returns the negative of this integer.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val x: NonPositiveInteger = NonPositiveInteger.fromLong(-42)
val result: NonNegativeInteger = -x
val expected: NonNegativeInteger = NonNegativeInteger.fromLong(42)
check(result == expected)Content copied to clipboard
Calling from Java
Here's an example of calling this function from Java code:
final NonPositiveInteger x = NonPositiveInteger.fromLong(-42L);
final NonNegativeInteger result = x.unaryMinus();
final NonNegativeInteger expected = NonNegativeInteger.fromLong(42L);
final boolean check = result.equals(expected);
if (!check) throw new IllegalStateException("Check failed.");Content copied to clipboard