unaryMinus

Returns the negative of this integer.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

val x: NonNegativeInteger = NonNegativeInteger.fromLong(42)
val result: NonPositiveInteger = -x
val expected: NonPositiveInteger = NonPositiveInteger.fromLong(-42)
check(result == expected)

val zero: NonNegativeInteger = NonNegativeInteger.fromLong(0)
check(-zero == NonPositiveInteger.fromLong(0))

Calling from Java

Here's an example of calling this function from Java code:

final NonNegativeInteger x = NonNegativeInteger.fromLong(42L);
final NonPositiveInteger result = x.unaryMinus();
final NonPositiveInteger expected = NonPositiveInteger.fromLong(-42L);
final boolean check = result.equals(expected);
if (!check) throw new IllegalStateException("Check failed.");

final NonNegativeInteger zero = NonNegativeInteger.fromLong(0L);
final boolean zeroCheck =
zero.unaryMinus().equals(NonPositiveInteger.fromLong(0L));
if (!zeroCheck) throw new IllegalStateException("Check failed.");