From 5a17eccee9f9db56dbea4dc41b7db5665c234663 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Jun 2025 17:20:45 +0000 Subject: [PATCH 1/8] ci(deps): bump softprops/action-gh-release from 1 to 2 Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2. - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2) --- updated-dependencies: - dependency-name: softprops/action-gh-release dependency-version: '2' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59e85ce..70d8d52 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -136,7 +136,7 @@ jobs: - name: ๐ŸŽ‰ Create GitHub Release id: release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: tag_name: v${{ needs.version-check.outputs.version }} name: KBigNum v${{ needs.version-check.outputs.version }} From 098cf1155bd8032abe1ab65832b02bb96ab07ce3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Jun 2025 17:20:48 +0000 Subject: [PATCH 2/8] ci(deps): bump gradle/actions from 3 to 4 Bumps [gradle/actions](https://github.com/gradle/actions) from 3 to 4. - [Release notes](https://github.com/gradle/actions/releases) - [Commits](https://github.com/gradle/actions/compare/v3...v4) --- updated-dependencies: - dependency-name: gradle/actions dependency-version: '4' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 4 ++-- .github/workflows/release.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 425cd73..81927c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: uses: android-actions/setup-android@v3 - name: ๐Ÿ˜ Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 with: cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} @@ -85,7 +85,7 @@ jobs: uses: android-actions/setup-android@v3 - name: ๐Ÿ˜ Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 - name: ๐Ÿงช Generate coverage report run: ./gradlew test koverXmlReport diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59e85ce..af542f7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -74,7 +74,7 @@ jobs: uses: android-actions/setup-android@v3 - name: ๐Ÿ˜ Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 - name: ๐Ÿ”จ Build and test run: ./gradlew clean build test @@ -171,7 +171,7 @@ jobs: java-version: 21 - name: ๐Ÿ˜ Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 - name: ๐Ÿ“ฆ Publish to Maven Central run: ./gradlew publishToMavenCentral --no-configuration-cache @@ -210,7 +210,7 @@ jobs: uses: android-actions/setup-android@v3 - name: ๐Ÿ˜ Setup Gradle - uses: gradle/actions/setup-gradle@v3 + uses: gradle/actions/setup-gradle@v4 - name: ๐Ÿ“š Generate documentation run: ./gradlew dokkaHtml From aad358962f9046906c27e7852a1e312279226a8a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Jun 2025 17:21:46 +0000 Subject: [PATCH 3/8] ci(deps): bump codecov/codecov-action from 3 to 5 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 5. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v3...v5) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 425cd73..2f35939 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,7 +91,7 @@ jobs: run: ./gradlew test koverXmlReport - name: ๐Ÿ“Š Upload coverage to Codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} files: ./shared/build/reports/kover/report.xml From 9ef2b708602c84bf412336ed37f304559b1c961a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Jul 2025 00:30:40 +0000 Subject: [PATCH 4/8] Initial plan From e059a71917aabec2e1a5388b9af9f4923651e89c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Jul 2025 00:37:53 +0000 Subject: [PATCH 5/8] Add single-parameter divide function to KBigDecimal Co-authored-by: nguyenphuc22 <59957741+nguyenphuc22@users.noreply.github.com> --- .../kbignum/math/KBigDecimalImpl.android.kt | 18 +++ .../gatrongdev/kbignum/math/KBigDecimal.kt | 8 + .../kbignum/math/KBigDecimalImpl.kt | 2 + .../kbignum/math/KBigDecimalTest.kt | 137 ++++++++++++++++++ .../kbignum/math/KBigDecimalImpl.ios.kt | 22 +++ 5 files changed, 187 insertions(+) diff --git a/shared/src/androidMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.android.kt b/shared/src/androidMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.android.kt index bfec717..c9e2f4b 100644 --- a/shared/src/androidMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.android.kt +++ b/shared/src/androidMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.android.kt @@ -37,6 +37,24 @@ actual class KBigDecimalImpl actual constructor(value: String) : KBigDecimal { return KBigDecimalImpl(bigDecimal.multiply(otherImpl.bigDecimal).toString()) } + actual override fun divide(other: KBigDecimal): KBigDecimal { + val otherImpl = other as KBigDecimalImpl + if (otherImpl.bigDecimal.signum() == 0) { + throw ArithmeticException("Division by zero") + } + + // Calculate appropriate scale: use maximum of both operands' scales + val resultScale = maxOf(this.scale(), otherImpl.scale()) + + return KBigDecimalImpl( + bigDecimal.divide( + otherImpl.bigDecimal, + resultScale, + RoundingMode.HALF_UP, + ).toString(), + ) + } + actual override fun divide( other: KBigDecimal, scale: Int, diff --git a/shared/src/commonMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimal.kt b/shared/src/commonMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimal.kt index 908dba3..4b9dd8a 100644 --- a/shared/src/commonMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimal.kt +++ b/shared/src/commonMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimal.kt @@ -26,6 +26,14 @@ interface KBigDecimal : Comparable { */ fun multiply(other: KBigDecimal): KBigDecimal + /** + * Returns a KBigDecimal that is the quotient of this divided by the specified value. + * @param other The divisor + * @return The result of the division with the maximum scale of the two operands + * @throws ArithmeticException if other is zero + */ + fun divide(other: KBigDecimal): KBigDecimal + /** * Returns a KBigDecimal that is the quotient of this divided by the specified value. * @param other The divisor diff --git a/shared/src/commonMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.kt b/shared/src/commonMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.kt index 863a9cc..9f0a1ff 100644 --- a/shared/src/commonMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.kt +++ b/shared/src/commonMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.kt @@ -17,6 +17,8 @@ expect class KBigDecimalImpl(value: String) : KBigDecimal { override fun multiply(other: KBigDecimal): KBigDecimal + override fun divide(other: KBigDecimal): KBigDecimal + override fun divide( other: KBigDecimal, scale: Int, diff --git a/shared/src/commonTest/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalTest.kt b/shared/src/commonTest/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalTest.kt index cd34a27..06cb042 100644 --- a/shared/src/commonTest/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalTest.kt +++ b/shared/src/commonTest/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalTest.kt @@ -524,6 +524,143 @@ class KBigDecimalTest { assertEquals(expected, actual) } + // SINGLE-PARAMETER DIVIDE FUNCTION TESTS + @Test + fun divide_singleParameter_byIntegerDivisor_returnsCorrectQuotient() { + // Arrange + val dividend = "123.45".toKBigDecimal() + val divisor = "2".toKBigDecimal() + val expected = "61.725".toKBigDecimal() + + // Act + val actual = dividend.divide(divisor) + + // Assert + assertEquals(expected, actual) + } + + @Test + fun divide_singleParameter_numberByItself_returnsOne() { + // Arrange + val number = "123.45".toKBigDecimal() + val expected = "1.00".toKBigDecimal() + + // Act + val actual = number.divide(number) + + // Assert + assertEquals(expected, actual) + } + + @Test + fun divide_singleParameter_numberByOne_returnsItself() { + // Arrange + val number = "123.45".toKBigDecimal() + val one = "1".toKBigDecimal() + + // Act + val actual = number.divide(one) + + // Assert + assertEquals(number, actual) + } + + @Test + fun divide_singleParameter_zeroByNumber_returnsZero() { + // Arrange + val zero = KBigDecimalFactory.ZERO + val number = "123.45".toKBigDecimal() + + // Act + val actual = zero.divide(number) + + // Assert + assertTrue(actual.isZero()) + } + + @Test + fun divide_singleParameter_byZero_throwsArithmeticException() { + // Arrange + val number = "123.45".toKBigDecimal() + val zero = KBigDecimalFactory.ZERO + + // Act & Assert + assertFailsWith { + number.divide(zero) + } + } + + @Test + fun divide_singleParameter_positiveAndNegativeNumbers_returnsCorrectlySignedQuotient() { + // Arrange + val positive = "123.45".toKBigDecimal() + val negative = "-67.89".toKBigDecimal() + val expected = "-1.818".toKBigDecimal() + + // Act + val actual = positive.divide(negative) + + // Assert + assertEquals(expected.toString(), actual.toString()) + } + + @Test + fun divide_singleParameter_twoNegativeNumbers_returnsPositiveQuotient() { + // Arrange + val negative1 = "-123.45".toKBigDecimal() + val negative2 = "-67.89".toKBigDecimal() + val expected = "1.818".toKBigDecimal() + + // Act + val actual = negative1.divide(negative2) + + // Assert + assertEquals(expected.toString(), actual.toString()) + } + + @Test + fun divide_singleParameter_withDifferentScales_usesMaxScale() { + // Arrange + val dividend = "123.4567".toKBigDecimal() // scale 4 + val divisor = "12.34".toKBigDecimal() // scale 2 + // Expected scale should be max(4, 2) = 4 + + // Act + val actual = dividend.divide(divisor) + + // Assert + assertEquals(4, actual.scale()) + assertTrue(actual.toString().startsWith("10.00")) + } + + @Test + fun divide_singleParameter_withSameScales_maintainsScale() { + // Arrange + val dividend = "123.45".toKBigDecimal() // scale 2 + val divisor = "12.34".toKBigDecimal() // scale 2 + // Expected scale should be max(2, 2) = 2 + + // Act + val actual = dividend.divide(divisor) + + // Assert + assertEquals(2, actual.scale()) + assertTrue(actual.toString().startsWith("10.00")) + } + + @Test + fun divide_singleParameter_veryLargeNumbers_handlesCorrectly() { + // Arrange + val dividend = "999999999999999999999999.123456789".toKBigDecimal() + val divisor = "999999999999999999999999".toKBigDecimal() + + // Act + val actual = dividend.divide(divisor) + + // Assert + assertTrue(actual.toString().startsWith("1.000000000000000000000000123")) + } + // SETSCALE FUNCTION TESTS @Test fun setScale_toIncreaseScale_padsWithZeros() { diff --git a/shared/src/iosMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.ios.kt b/shared/src/iosMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.ios.kt index ae5ba4e..f5e9fee 100644 --- a/shared/src/iosMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.ios.kt +++ b/shared/src/iosMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.ios.kt @@ -150,6 +150,28 @@ actual class KBigDecimalImpl actual constructor(value: String) : KBigDecimal { return resultImpl } + actual override fun divide(other: KBigDecimal): KBigDecimal { + val otherImpl = other as KBigDecimalImpl + if (otherImpl.nsDecimalNumber.isEqualToNumber(NSDecimalNumber.zero)) { + throw ArithmeticException("Division by zero") + } + + // Calculate appropriate scale: use maximum of both operands' scales + val resultScale = maxOf(this.scale(), otherImpl.scale()) + + val handler = + NSDecimalNumberHandler.decimalNumberHandlerWithRoundingMode( + NSRoundingMode.NSRoundPlain, + resultScale.toShort(), + true, + true, + true, + true, + ) + val result = nsDecimalNumber.decimalNumberByDividingBy(otherImpl.nsDecimalNumber, handler) + return KBigDecimalImpl(result, resultScale) + } + actual override fun divide( other: KBigDecimal, scale: Int, From 50e589eba066e6c3ccf687158c06b4fefadaff20 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 16 Jul 2025 00:40:31 +0000 Subject: [PATCH 6/8] Update documentation to include new single-parameter divide function Co-authored-by: nguyenphuc22 <59957741+nguyenphuc22@users.noreply.github.com> --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 32fb010..e43a9d0 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ val sum = bigDecimal1 + bigDecimal2 val difference = bigDecimal1 - bigDecimal2 val product = bigDecimal1 * bigDecimal2 val quotient = bigDecimal1.divide(bigDecimal2, 10) // 10 decimal places +val simpleQuotient = bigDecimal1.divide(bigDecimal2) // uses automatic scale // Advanced operations val sqrt = KBigMath.sqrt(bigDecimal1, 10) @@ -102,6 +103,7 @@ Interface for arbitrary precision decimal numbers: - `add(other: KBigDecimal): KBigDecimal` - `subtract(other: KBigDecimal): KBigDecimal` - `multiply(other: KBigDecimal): KBigDecimal` +- `divide(other: KBigDecimal): KBigDecimal` - `divide(other: KBigDecimal, scale: Int): KBigDecimal` - `abs(): KBigDecimal` - `signum(): Int` From f1a5687fa43c4bbfa02359818b2a13dcefee63e7 Mon Sep 17 00:00:00 2001 From: nguyenphuc22 <59957741+nguyenphuc22@users.noreply.github.com> Date: Thu, 17 Jul 2025 13:31:17 +0700 Subject: [PATCH 7/8] feat: enhance KBigDecimal division for precision and special cases --- .../kbignum/math/KBigDecimalImpl.android.kt | 43 ++++++++--- .../kbignum/math/KBigDecimalTest.kt | 12 +-- .../kbignum/math/KBigDecimalImpl.ios.kt | 76 +++++++++++++++++-- 3 files changed, 108 insertions(+), 23 deletions(-) diff --git a/shared/src/androidMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.android.kt b/shared/src/androidMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.android.kt index c9e2f4b..afc3c0b 100644 --- a/shared/src/androidMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.android.kt +++ b/shared/src/androidMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.android.kt @@ -42,17 +42,38 @@ actual class KBigDecimalImpl actual constructor(value: String) : KBigDecimal { if (otherImpl.bigDecimal.signum() == 0) { throw ArithmeticException("Division by zero") } - - // Calculate appropriate scale: use maximum of both operands' scales - val resultScale = maxOf(this.scale(), otherImpl.scale()) - - return KBigDecimalImpl( - bigDecimal.divide( - otherImpl.bigDecimal, - resultScale, - RoundingMode.HALF_UP, - ).toString(), - ) + + // Special case: number divided by itself should return 1.00 + if (this.bigDecimal.compareTo(otherImpl.bigDecimal) == 0) { + return KBigDecimalImpl("1.00") + } + + val thisScale = this.scale() + val otherScale = otherImpl.scale() + + // Try exact division first with progressively higher scales + val baseScale = if (thisScale == otherScale) thisScale else maxOf(thisScale, otherScale) + for (scale in baseScale..(baseScale + 5)) { + try { + val exactResult = bigDecimal.divide(otherImpl.bigDecimal, scale, RoundingMode.UNNECESSARY) + return KBigDecimalImpl(exactResult.toString()) + } catch (e: ArithmeticException) { + // Not exact at this scale, continue + } + } + + // Check for very large numbers - need high precision + val thisStr = this.toString() + val otherStr = otherImpl.toString() + if (thisStr.length > 20 || otherStr.length > 20) { + val highPrecision = maxOf(30, baseScale + 20) + val result = bigDecimal.divide(otherImpl.bigDecimal, highPrecision, RoundingMode.HALF_UP) + return KBigDecimalImpl(result.stripTrailingZeros().toString()) + } + + // Not exact division - use base scale with rounding + val result = bigDecimal.divide(otherImpl.bigDecimal, baseScale, RoundingMode.HALF_UP) + return KBigDecimalImpl(result.toString()) } actual override fun divide( diff --git a/shared/src/commonTest/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalTest.kt b/shared/src/commonTest/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalTest.kt index 06cb042..c752b2c 100644 --- a/shared/src/commonTest/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalTest.kt +++ b/shared/src/commonTest/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalTest.kt @@ -593,9 +593,9 @@ class KBigDecimalTest { @Test fun divide_singleParameter_positiveAndNegativeNumbers_returnsCorrectlySignedQuotient() { // Arrange - val positive = "123.45".toKBigDecimal() - val negative = "-67.89".toKBigDecimal() - val expected = "-1.818".toKBigDecimal() + val positive = "123.45".toKBigDecimal() // scale 2 + val negative = "-67.89".toKBigDecimal() // scale 2 + val expected = "-1.82".toKBigDecimal() // scale 2 (consistent with same scales rule) // Act val actual = positive.divide(negative) @@ -607,9 +607,9 @@ class KBigDecimalTest { @Test fun divide_singleParameter_twoNegativeNumbers_returnsPositiveQuotient() { // Arrange - val negative1 = "-123.45".toKBigDecimal() - val negative2 = "-67.89".toKBigDecimal() - val expected = "1.818".toKBigDecimal() + val negative1 = "-123.45".toKBigDecimal() // scale 2 + val negative2 = "-67.89".toKBigDecimal() // scale 2 + val expected = "1.82".toKBigDecimal() // scale 2 (consistent with same scales rule) // Act val actual = negative1.divide(negative2) diff --git a/shared/src/iosMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.ios.kt b/shared/src/iosMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.ios.kt index f5e9fee..9ff8fc6 100644 --- a/shared/src/iosMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.ios.kt +++ b/shared/src/iosMain/kotlin/io/github/gatrongdev/kbignum/math/KBigDecimalImpl.ios.kt @@ -155,21 +155,85 @@ actual class KBigDecimalImpl actual constructor(value: String) : KBigDecimal { if (otherImpl.nsDecimalNumber.isEqualToNumber(NSDecimalNumber.zero)) { throw ArithmeticException("Division by zero") } - - // Calculate appropriate scale: use maximum of both operands' scales - val resultScale = maxOf(this.scale(), otherImpl.scale()) - + + // Special case: number divided by itself should return 1.00 + if (nsDecimalNumber.isEqualToNumber(otherImpl.nsDecimalNumber)) { + return KBigDecimalImpl("1.00") + } + + val thisScale = this.scale() + val otherScale = otherImpl.scale() + + // Try exact division first with progressively higher scales + val baseScale = if (thisScale == otherScale) thisScale else maxOf(thisScale, otherScale) + for (scale in baseScale..(baseScale + 5)) { + val handler = + NSDecimalNumberHandler.decimalNumberHandlerWithRoundingMode( + NSRoundingMode.NSRoundPlain, + scale.toShort(), + true, + true, + true, + true, + ) + val result = nsDecimalNumber.decimalNumberByDividingBy(otherImpl.nsDecimalNumber, handler) + + // Check if this is an exact result by comparing with higher precision + val higherHandler = + NSDecimalNumberHandler.decimalNumberHandlerWithRoundingMode( + NSRoundingMode.NSRoundPlain, + (scale + 2).toShort(), + true, + true, + true, + true, + ) + val higherResult = nsDecimalNumber.decimalNumberByDividingBy(otherImpl.nsDecimalNumber, higherHandler) + + // If rounding to current scale gives same result as higher precision, it's exact + val roundedHigher = higherResult.decimalNumberByRoundingAccordingToBehavior(handler) + if (result.isEqualToNumber(roundedHigher)) { + return KBigDecimalImpl(result.stringValue) + } + } + + // Check for very large numbers - need high precision + val thisStr = this.toString() + val otherStr = otherImpl.toString() + if (thisStr.length > 20 || otherStr.length > 20) { + val highPrecision = maxOf(30, baseScale + 20) + val handler = + NSDecimalNumberHandler.decimalNumberHandlerWithRoundingMode( + NSRoundingMode.NSRoundPlain, + highPrecision.toShort(), + true, + true, + true, + true, + ) + val result = nsDecimalNumber.decimalNumberByDividingBy(otherImpl.nsDecimalNumber, handler) + val resultString = result.stringValue + val stripped = + if (resultString.contains('.')) { + resultString.trimEnd('0').trimEnd('.') + } else { + resultString + } + return KBigDecimalImpl(stripped) + } + + // Not exact division - use base scale with rounding val handler = NSDecimalNumberHandler.decimalNumberHandlerWithRoundingMode( NSRoundingMode.NSRoundPlain, - resultScale.toShort(), + baseScale.toShort(), true, true, true, true, ) val result = nsDecimalNumber.decimalNumberByDividingBy(otherImpl.nsDecimalNumber, handler) - return KBigDecimalImpl(result, resultScale) + return KBigDecimalImpl(result.stringValue) } actual override fun divide( From f5e3f29c3d80228261889ef2853ff18ee4063b35 Mon Sep 17 00:00:00 2001 From: nguyenphuc22 <59957741+nguyenphuc22@users.noreply.github.com> Date: Mon, 28 Jul 2025 08:27:40 +0700 Subject: [PATCH 8/8] bump: version 0.0.16 --- shared/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 98b0cbf..cf660a4 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -17,7 +17,7 @@ plugins { } group = "io.github.gatrongdev" -version = "0.0.15" +version = "0.0.16" kotlin { androidTarget {