Skip to content

Commit

Permalink
fix big integer for native
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypfau committed Feb 7, 2023
1 parent 4a223ef commit f2a504f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ https://github.com/andreypfau/ton-kotlin/wiki/TON-Kotlin-documentation
[telegram]: https://t.me/tonkotlin

[maven-central-svg]: https://img.shields.io/maven-central/v/org.ton/ton-kotlin?color=blue
[kotlin-svg]: https://img.shields.io/badge/Kotlin-1.8.0-blue.svg?logo=kotlin
[kotlin-svg]: https://img.shields.io/badge/Kotlin-1.8.10-blue.svg?logo=kotlin
[telegram-svg]: https://img.shields.io/badge/Telegram-join%20chat-blue.svg?logo=telegram
[ton-svg]: https://img.shields.io/badge/Based%20on-TON-blue
[license-svg]: https://img.shields.io/github/license/andreypfau/ton-kotlin?color=blue
3 changes: 1 addition & 2 deletions ton-kotlin-bigint/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(projects.tonKotlinCrypto)
implementation(libs.serialization.json)
implementation(libs.atomicfu)
implementation("com.ionspin.kotlin:bignum:0.3.7")
}
}
val commonTest by getting
Expand Down
13 changes: 11 additions & 2 deletions ton-kotlin-bigint/src/nativeMain/kotlin/org/ton/bigint/BigInt.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ton.bigint

import com.ionspin.kotlin.bignum.integer.BigInteger
import com.ionspin.kotlin.bignum.integer.BigIntegerArithmetic
import com.ionspin.kotlin.bignum.integer.util.fromTwosComplementByteArray

@Suppress("ConvertSecondaryConstructorToPrimary")
Expand Down Expand Up @@ -50,8 +51,16 @@ public actual fun Int.toBigInt(): BigInt =
public actual fun Long.toBigInt(): BigInt =
BigInt(BigInteger.fromLong(this))

public actual val BigInt.bitLength: Int get() =
TODO()
public actual val BigInt.bitLength: Int get() {
// TODO: https://github.com/ionspin/kotlin-multiplatform-bignum/pull/254
return if (value.isNegative) {
if (value == BigInteger.ONE.negate()) 0
else (value.abs() - 1).toString(2).length
} else {
if (value.isZero()) 0
else value.toString(2).length
}
}

public actual val BigInt.sign: Int get() =
value.signum()
Expand Down

0 comments on commit f2a504f

Please sign in to comment.