Skip to content

Commit d594d5b

Browse files
revert(core): "remove Long constructor from JS"
This reverts commit d3a3315
1 parent b1bcc3d commit d594d5b

File tree

6 files changed

+17
-10
lines changed
  • kbigint/src
    • androidMain/kotlin/io/github/observeroftime/kbigint
    • commonMain/kotlin/io/github/observeroftime/kbigint
    • jsMain/kotlin/io/github/observeroftime/kbigint
    • jsTest/kotlin/io/github/observeroftime/kbigint
    • jvmMain/kotlin/io/github/observeroftime/kbigint
    • nativeMain/kotlin/io/github/observeroftime/kbigint

6 files changed

+17
-10
lines changed

kbigint/src/androidMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ actual class KBigInt private constructor(private var value: BigInteger) : Compar
1111

1212
actual constructor(number: Int) : this(number.toBigInteger())
1313

14-
constructor(number: Long) : this(number.toBigInteger())
14+
actual constructor(number: Long) : this(number.toBigInteger())
1515

1616
/** Convert a [ByteArray] to a [KBigInt]. */
1717
@Suppress("unused")

kbigint/src/commonMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ expect class KBigInt : Comparable<KBigInt> {
88
/** Convert an [Int] to a [KBigInt]. */
99
constructor(number: Int)
1010

11+
/** Convert a [Long] to a [KBigInt]. */
12+
constructor(number: Long)
13+
1114
/**
1215
* The sign of the value:
1316
*

kbigint/src/jsMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ actual class KBigInt private constructor(@JsExternalArgument private var value:
1010
@JsName("fromNumber")
1111
actual constructor(number: Int) : this(BigInt(number))
1212

13+
@JsName("_fromLong")
14+
@Suppress("NON_EXPORTABLE_TYPE")
15+
actual constructor(number: Long) : this(BigInt(number))
16+
1317
actual val sign: Int
1418
get() = KBigIntUtils.sign(value)
1519

kbigint/src/jsTest/kotlin/io/github/observeroftime/kbigint/KBigIntTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import kotlin.test.*
44

55
actual class KBigIntTest {
66
companion object {
7-
private val long = KBigInt(OVER_MAX_INT.toString())
7+
private val long = KBigInt(OVER_MAX_INT)
88
private val string = KBigInt(OVER_MAX_LONG)
99
}
1010

@@ -20,7 +20,7 @@ actual class KBigIntTest {
2020
assertEquals(KBigInt("9223372039002259456"), string + long)
2121
assertEquals(KBigInt("9223372034707292160"), string - long)
2222
assertEquals(KBigInt("19807040628566084398385987584"), string * long)
23-
assertEquals(KBigInt("4294967296"), string / long)
23+
assertEquals(KBigInt(4294967296L), string / long)
2424
assertEquals(KBigInt(0), string % long)
2525
}
2626

@@ -33,7 +33,7 @@ actual class KBigIntTest {
3333

3434
@Test
3535
actual fun testNegate() {
36-
assertEquals(KBigInt((-OVER_MAX_INT).toString()), -long)
36+
assertEquals(KBigInt(-OVER_MAX_INT), -long)
3737
}
3838

3939
@Test
@@ -45,13 +45,13 @@ actual class KBigIntTest {
4545

4646
@Test
4747
actual fun testShifts() {
48-
assertEquals(KBigInt("8589934592"), long shl 2)
49-
assertEquals(KBigInt(1073741824), long shr 1)
48+
assertEquals(KBigInt(8589934592L), long shl 2)
49+
assertEquals(KBigInt(1073741824L), long shr 1)
5050
}
5151

5252
@Test
5353
actual fun testInvert() {
54-
assertEquals(KBigInt("-2147483649"), long.inv())
54+
assertEquals(KBigInt(-2147483649L), long.inv())
5555
}
5656

5757
@Test
@@ -85,7 +85,7 @@ actual class KBigIntTest {
8585
@Test
8686
actual fun testEquals() {
8787
assertFalse { long == string }
88-
assertTrue { long == KBigInt(OVER_MAX_INT.toString()) }
88+
assertTrue { long == KBigInt(OVER_MAX_INT) }
8989
}
9090

9191
@Test

kbigint/src/jvmMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ actual class KBigInt private constructor(private var value: BigInteger) : Compar
99

1010
actual constructor(number: Int) : this(number.toBigInteger())
1111

12-
constructor(number: Long) : this(number.toBigInteger())
12+
actual constructor(number: Long) : this(number.toBigInteger())
1313

1414
/** Convert a [ByteArray] to a [KBigInt]. */
1515
@Suppress("unused")

kbigint/src/nativeMain/kotlin/io/github/observeroftime/kbigint/KBigInt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ actual class KBigInt private constructor(private var value: mp_int) : Comparable
4848
* @throws [IllegalStateException] if the operation fails
4949
*/
5050
@Throws(IllegalStateException::class)
51-
constructor(number: Long) : this() {
51+
actual constructor(number: Long) : this() {
5252
mp_init_i64(value.ptr, number).check()
5353
}
5454

0 commit comments

Comments
 (0)