Skip to content

Commit

Permalink
revert(core): "remove Long constructor from JS"
Browse files Browse the repository at this point in the history
This reverts commit d3a3315
  • Loading branch information
ObserverOfTime committed Apr 24, 2024
1 parent b1bcc3d commit d594d5b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ actual class KBigInt private constructor(private var value: BigInteger) : Compar

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

constructor(number: Long) : this(number.toBigInteger())
actual constructor(number: Long) : this(number.toBigInteger())

/** Convert a [ByteArray] to a [KBigInt]. */
@Suppress("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ expect class KBigInt : Comparable<KBigInt> {
/** Convert an [Int] to a [KBigInt]. */
constructor(number: Int)

/** Convert a [Long] to a [KBigInt]. */
constructor(number: Long)

/**
* The sign of the value:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ actual class KBigInt private constructor(@JsExternalArgument private var value:
@JsName("fromNumber")
actual constructor(number: Int) : this(BigInt(number))

@JsName("_fromLong")
@Suppress("NON_EXPORTABLE_TYPE")
actual constructor(number: Long) : this(BigInt(number))

actual val sign: Int
get() = KBigIntUtils.sign(value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlin.test.*

actual class KBigIntTest {
companion object {
private val long = KBigInt(OVER_MAX_INT.toString())
private val long = KBigInt(OVER_MAX_INT)
private val string = KBigInt(OVER_MAX_LONG)
}

Expand All @@ -20,7 +20,7 @@ actual class KBigIntTest {
assertEquals(KBigInt("9223372039002259456"), string + long)
assertEquals(KBigInt("9223372034707292160"), string - long)
assertEquals(KBigInt("19807040628566084398385987584"), string * long)
assertEquals(KBigInt("4294967296"), string / long)
assertEquals(KBigInt(4294967296L), string / long)
assertEquals(KBigInt(0), string % long)
}

Expand All @@ -33,7 +33,7 @@ actual class KBigIntTest {

@Test
actual fun testNegate() {
assertEquals(KBigInt((-OVER_MAX_INT).toString()), -long)
assertEquals(KBigInt(-OVER_MAX_INT), -long)
}

@Test
Expand All @@ -45,13 +45,13 @@ actual class KBigIntTest {

@Test
actual fun testShifts() {
assertEquals(KBigInt("8589934592"), long shl 2)
assertEquals(KBigInt(1073741824), long shr 1)
assertEquals(KBigInt(8589934592L), long shl 2)
assertEquals(KBigInt(1073741824L), long shr 1)
}

@Test
actual fun testInvert() {
assertEquals(KBigInt("-2147483649"), long.inv())
assertEquals(KBigInt(-2147483649L), long.inv())
}

@Test
Expand Down Expand Up @@ -85,7 +85,7 @@ actual class KBigIntTest {
@Test
actual fun testEquals() {
assertFalse { long == string }
assertTrue { long == KBigInt(OVER_MAX_INT.toString()) }
assertTrue { long == KBigInt(OVER_MAX_INT) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ actual class KBigInt private constructor(private var value: BigInteger) : Compar

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

constructor(number: Long) : this(number.toBigInteger())
actual constructor(number: Long) : this(number.toBigInteger())

/** Convert a [ByteArray] to a [KBigInt]. */
@Suppress("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ actual class KBigInt private constructor(private var value: mp_int) : Comparable
* @throws [IllegalStateException] if the operation fails
*/
@Throws(IllegalStateException::class)
constructor(number: Long) : this() {
actual constructor(number: Long) : this() {
mp_init_i64(value.ptr, number).check()
}

Expand Down

0 comments on commit d594d5b

Please sign in to comment.