From 8b171ac3a353e0831e18045ccb7732272ac74f11 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Sat, 12 Sep 2020 09:22:26 +0700 Subject: [PATCH] Update changelog --- CHANGELOG.md | 2 +- .../scientifik/kmath/operations/BigInt.kt | 24 +++++++++---------- .../scientifik/kmath/functions/Polynomial.kt | 6 ++--- .../scientifik/kmath/viktor/ViktorBuffer.kt | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3944c673e..cf42a33e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ - `power(T, Int)` extension function has preconditions and supports `Field` - Memory objects have more preconditions (overflow checking) - `tg` function is renamed to `tan` (https://github.com/mipt-npm/kmath/pull/114) -- Gradle version: 6.3 -> 6.6 +- Gradle version: 6.3 -> 6.6.1 - Moved probability distributions to commons-rng and to `kmath-prob` ### Fixed diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt index fbb60026e..d54557a1f 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt @@ -255,9 +255,9 @@ public class BigInt internal constructor( } private fun addMagnitudes(mag1: Magnitude, mag2: Magnitude): Magnitude { - val resultLength: Int = max(mag1.size, mag2.size) + 1 + val resultLength = max(mag1.size, mag2.size) + 1 val result = Magnitude(resultLength) - var carry: TBase = 0UL + var carry = 0uL for (i in 0 until resultLength - 1) { val res = when { @@ -265,20 +265,22 @@ public class BigInt internal constructor( i >= mag2.size -> mag1[i].toULong() + carry else -> mag1[i].toULong() + mag2[i].toULong() + carry } + result[i] = (res and BASE).toUInt() carry = (res shr BASE_SIZE) } + result[resultLength - 1] = carry.toUInt() return stripLeadingZeros(result) } private fun subtractMagnitudes(mag1: Magnitude, mag2: Magnitude): Magnitude { - val resultLength: Int = mag1.size + val resultLength = mag1.size val result = Magnitude(resultLength) var carry = 0L for (i in 0 until resultLength) { - var res: Long = + var res = if (i < mag2.size) mag1[i].toLong() - mag2[i].toLong() - carry else mag1[i].toLong() - carry @@ -292,9 +294,9 @@ public class BigInt internal constructor( } private fun multiplyMagnitudeByUInt(mag: Magnitude, x: UInt): Magnitude { - val resultLength: Int = mag.size + 1 + val resultLength = mag.size + 1 val result = Magnitude(resultLength) - var carry: ULong = 0UL + var carry = 0uL for (i in mag.indices) { val cur: ULong = carry + mag[i].toULong() * x.toULong() @@ -307,11 +309,11 @@ public class BigInt internal constructor( } private fun multiplyMagnitudes(mag1: Magnitude, mag2: Magnitude): Magnitude { - val resultLength: Int = mag1.size + mag2.size + val resultLength = mag1.size + mag2.size val result = Magnitude(resultLength) for (i in mag1.indices) { - var carry: ULong = 0UL + var carry = 0uL for (j in mag2.indices) { val cur: ULong = result[i + j].toULong() + mag1[i].toULong() * mag2[j].toULong() + carry @@ -338,9 +340,7 @@ public class BigInt internal constructor( return stripLeadingZeros(result) } - } - } private fun stripLeadingZeros(mag: Magnitude): Magnitude { @@ -366,7 +366,8 @@ public fun Int.toBigInt(): BigInt = BigInt(sign.toByte(), uintArrayOf(kotlin.mat * Convert this [Long] to [BigInt] */ public fun Long.toBigInt(): BigInt = BigInt( - sign.toByte(), stripLeadingZeros( + sign.toByte(), + stripLeadingZeros( uintArrayOf( (kotlin.math.abs(this).toULong() and BASE).toUInt(), ((kotlin.math.abs(this).toULong() shr BASE_SIZE) and BASE).toUInt() @@ -384,7 +385,6 @@ public fun UInt.toBigInt(): BigInt = BigInt(1, uintArrayOf(this)) */ public fun ULong.toBigInt(): BigInt = BigInt( 1, - stripLeadingZeros( uintArrayOf( (this and BASE).toUInt(), diff --git a/kmath-functions/src/commonMain/kotlin/scientifik/kmath/functions/Polynomial.kt b/kmath-functions/src/commonMain/kotlin/scientifik/kmath/functions/Polynomial.kt index 6eadf4301..3d97936f9 100644 --- a/kmath-functions/src/commonMain/kotlin/scientifik/kmath/functions/Polynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/scientifik/kmath/functions/Polynomial.kt @@ -13,9 +13,9 @@ import kotlin.math.pow * Polynomial coefficients without fixation on specific context they are applied to * @param coefficients constant is the leftmost coefficient */ -public /*inline*/ class Polynomial(public val coefficients: List) { - public constructor(vararg coefficients: T) : this(coefficients.toList()) -} +public inline class Polynomial(public val coefficients: List) + +public fun Polynomial(vararg coefficients: T): Polynomial = Polynomial(coefficients.toList()) public fun Polynomial.value(): Double = coefficients.reduceIndexed { index, acc, d -> acc + d.pow(index) } diff --git a/kmath-viktor/src/main/kotlin/scientifik/kmath/viktor/ViktorBuffer.kt b/kmath-viktor/src/main/kotlin/scientifik/kmath/viktor/ViktorBuffer.kt index be5bf5740..97ab9e6d7 100644 --- a/kmath-viktor/src/main/kotlin/scientifik/kmath/viktor/ViktorBuffer.kt +++ b/kmath-viktor/src/main/kotlin/scientifik/kmath/viktor/ViktorBuffer.kt @@ -10,7 +10,7 @@ public inline class ViktorBuffer(public val flatArray: F64FlatArray) : MutableBu public override inline fun get(index: Int): Double = flatArray[index] - override inline fun set(index: Int, value: Double) { + public override inline fun set(index: Int, value: Double) { flatArray[index] = value }