File tree Expand file tree Collapse file tree 10 files changed +68
-33
lines changed
androidMain/kotlin/io/github/observeroftime/kbigint
androidUnitTest/kotlin/io/github/observeroftime/kbigint
commonMain/kotlin/io/github/observeroftime/kbigint
commonTest/kotlin/io/github/observeroftime/kbigint
jsMain/kotlin/io/github/observeroftime/kbigint
jsTest/kotlin/io/github/observeroftime/kbigint
jvmMain/kotlin/io/github/observeroftime/kbigint
jvmTest/kotlin/io/github/observeroftime/kbigint
nativeMain/kotlin/io/github/observeroftime/kbigint
nativeTest/kotlin/io/github/observeroftime/kbigint Expand file tree Collapse file tree 10 files changed +68
-33
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,13 @@ actual class KBigInt private constructor(private var value: BigInteger) : Compar
9090 @JvmName(" negate" )
9191 actual operator fun unaryMinus () = KBigInt (- value)
9292
93+ /* *
94+ * Compute the two's-complement of the value.
95+ *
96+ * @since 0.5.0
97+ */
98+ actual operator fun not () = KBigInt (! value)
99+
93100 /* * Perform a bitwise `AND` operation. */
94101 actual infix fun and (other : KBigInt ) = KBigInt (value and other.value)
95102
@@ -217,8 +224,8 @@ actual class KBigInt private constructor(private var value: BigInteger) : Compar
217224 }
218225
219226 /* * Compute the two's-complement of the value. */
220- @JvmName( " not" )
221- actual fun inv () = KBigInt ( ! value )
227+ @Deprecated( " Use the not operator instead " , ReplaceWith ( " !this " ) )
228+ actual fun inv () = not ( )
222229
223230 /* * Get the absolute value. */
224231 actual fun abs () = KBigInt (value.abs())
Original file line number Diff line number Diff line change @@ -73,9 +73,9 @@ actual class KBigIntTest {
7373 }
7474
7575 @Test
76- actual fun testInvert () {
77- assertEquals(KBigInt (- 2147483649L ), long. inv () )
78- assertEquals(KBigInt (2147483649L ), - long. inv () )
76+ actual fun testNot () {
77+ assertEquals(KBigInt (- 2147483649L ), ! long)
78+ assertEquals(KBigInt (2147483649L ), - ! long)
7979 }
8080
8181 @Test
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ expect class KBigInt : Comparable<KBigInt> {
6666 /* * Negate the value. */
6767 operator fun unaryMinus (): KBigInt
6868
69+ /* *
70+ * Compute the two's-complement of the value.
71+ *
72+ * @since 0.5.0
73+ */
74+ operator fun not (): KBigInt
75+
6976 /* * Perform a bitwise `AND` operation. */
7077 infix fun and (other : KBigInt ): KBigInt
7178
@@ -133,11 +140,8 @@ expect class KBigInt : Comparable<KBigInt> {
133140 */
134141 fun sqrt (): KBigInt
135142
136- /* *
137- * Compute the two's-complement of the value.
138- *
139- * @throws [ArithmeticException] if the value is negative
140- */
143+ /* * Compute the two's-complement of the value. */
144+ @Deprecated(" Use the not operator instead" , ReplaceWith (" !this" ))
141145 fun inv (): KBigInt
142146
143147 /* * Get the absolute value. */
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ expect class KBigIntTest {
1212 fun testNegate ()
1313 fun testBitOps ()
1414 fun testShifts ()
15- fun testInvert ()
15+ fun testNot ()
1616 fun testGcdLcm ()
1717 fun testPow ()
1818 fun testRoot ()
Original file line number Diff line number Diff line change @@ -114,6 +114,17 @@ actual class KBigInt private constructor(@JsExternalArgument private var value:
114114 return KBigInt (js(" -x" ).unsafeCast<BigInt >())
115115 }
116116
117+ /* *
118+ * Compute the two's-complement of the value.
119+ *
120+ * @since 0.5.0
121+ */
122+ @JsName(" not" )
123+ actual operator fun not (): KBigInt {
124+ val x = this .value
125+ return KBigInt (js(" ~x" ).unsafeCast<BigInt >())
126+ }
127+
117128 /* * Perform a bitwise `AND` operation. */
118129 actual infix fun and (other : KBigInt ): KBigInt {
119130 val a = this .value
@@ -241,11 +252,8 @@ actual class KBigInt private constructor(@JsExternalArgument private var value:
241252 }
242253
243254 /* * Compute the two's-complement of the value. */
244- @JsName(" not" )
245- actual fun inv (): KBigInt {
246- val x = this .value
247- return KBigInt (js(" ~x" ).unsafeCast<BigInt >())
248- }
255+ @Deprecated(" Use the not operator instead" , ReplaceWith (" !this" ))
256+ actual fun inv () = not ()
249257
250258 /* * Get the absolute value. */
251259 actual fun abs () = KBigInt (KBigIntUtils .abs(value))
Original file line number Diff line number Diff line change @@ -74,9 +74,9 @@ actual class KBigIntTest {
7474 }
7575
7676 @Test
77- actual fun testInvert () {
78- assertEquals(KBigInt (- 2147483649L ), long. inv () )
79- assertEquals(KBigInt (2147483649L ), - long. inv () )
77+ actual fun testNot () {
78+ assertEquals(KBigInt (- 2147483649L ), ! long)
79+ assertEquals(KBigInt (2147483649L ), - ! long)
8080 }
8181
8282 @Test
Original file line number Diff line number Diff line change 33package io.github.observeroftime.kbigint
44
55import java.math.BigInteger
6+ import kotlin.ArithmeticException
67import kotlin.math.floor
78import kotlin.math.log2
89
@@ -87,6 +88,13 @@ actual class KBigInt private constructor(private var value: BigInteger) : Compar
8788 @JvmName(" negate" )
8889 actual operator fun unaryMinus () = KBigInt (- value)
8990
91+ /* *
92+ * Compute the two's-complement of the value.
93+ *
94+ * @since 0.5.0
95+ */
96+ actual operator fun not () = KBigInt (! value)
97+
9098 /* * Perform a bitwise `AND` operation. */
9199 actual infix fun and (other : KBigInt ) = KBigInt (value and other.value)
92100
@@ -214,8 +222,8 @@ actual class KBigInt private constructor(private var value: BigInteger) : Compar
214222 }
215223
216224 /* * Compute the two's-complement of the value. */
217- @JvmName( " not" )
218- actual fun inv () = KBigInt ( ! value )
225+ @Deprecated( " Use the not operator instead " , ReplaceWith ( " !this " ) )
226+ actual fun inv () = not ( )
219227
220228 /* * Get the absolute value. */
221229 actual fun abs () = KBigInt (value.abs())
Original file line number Diff line number Diff line change @@ -74,9 +74,9 @@ actual class KBigIntTest {
7474 }
7575
7676 @Test
77- actual fun testInvert () {
78- assertEquals(KBigInt (- 2147483649L ), long. inv () )
79- assertEquals(KBigInt (2147483649L ), - long. inv () )
77+ actual fun testNot () {
78+ assertEquals(KBigInt (- 2147483649L ), ! long)
79+ assertEquals(KBigInt (2147483649L ), - ! long)
8080 }
8181
8282 @Test
Original file line number Diff line number Diff line change @@ -264,6 +264,17 @@ actual class KBigInt private constructor(private var value: mp_int) : Comparable
264264 KBigInt (result.ptr)
265265 }
266266
267+ /* *
268+ * Compute the two's-complement of the value.
269+ *
270+ * @since 0.5.0
271+ */
272+ actual operator fun not (): KBigInt = memScoped {
273+ val result = alloc< mp_int> ()
274+ mp_complement(value.ptr, result.ptr).check()
275+ KBigInt (result.ptr)
276+ }
277+
267278 /* *
268279 * Perform a bitwise `AND` operation.
269280 *
@@ -430,12 +441,9 @@ actual class KBigInt private constructor(private var value: mp_int) : Comparable
430441 *
431442 * @throws [IllegalStateException] if the operation fails
432443 */
433- @ObjCName(" not" )
434- actual fun inv () = memScoped {
435- val result = alloc< mp_int> ()
436- mp_complement(value.ptr, result.ptr).check()
437- KBigInt (result.ptr)
438- }
444+ @Suppress(" unused" ) // deprecating not enough I guess
445+ @Deprecated(" Use the not operator instead" , ReplaceWith (" !this" ))
446+ actual fun inv () = not ()
439447
440448 /* *
441449 * Get the absolute value.
Original file line number Diff line number Diff line change @@ -94,9 +94,9 @@ actual class KBigIntTest {
9494 }
9595
9696 @Test
97- actual fun testInvert () {
98- assertEquals(KBigInt (- 2147483649L ), long. inv () )
99- assertEquals(KBigInt (2147483649L ), - long. inv () )
97+ actual fun testNot () {
98+ assertEquals(KBigInt (- 2147483649L ), ! long)
99+ assertEquals(KBigInt (2147483649L ), - ! long)
100100 }
101101
102102 @Test
You can’t perform that action at this time.
0 commit comments