Skip to content

Commit

Permalink
Project architecture improvements (#2)
Browse files Browse the repository at this point in the history
* - Separated the BigDecimal and BigInteger implementations
- Prepared the project to be completely multiplatform ready
- Updated the publishing names
- Updated the README

* Added Kontinuum CI

* Run ktlintFormat

* Changed project version to 0.0.1

* Changed the project group id to reflect the one that Jitpack uses
  • Loading branch information
RiccardoM authored and ligi committed Apr 19, 2019
1 parent fd2e52b commit 84d02ed
Show file tree
Hide file tree
Showing 19 changed files with 437 additions and 54 deletions.
4 changes: 4 additions & 0 deletions .ci/kontinuum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type":"library",
"stages":["build"]
}
45 changes: 37 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,53 @@
[BigDecimal](https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html).

Currently this library is only compatible with `common` and `jvm` modules.
Any PR implementing more platforms are more than welcome.
Any PR implementing is platforms are more than welcome.

## Usage
Don't forget to declare a variable named `kbignumbers_version` equals to the latest version.
## Packages
The project is split into two different packages: `biginteger` and `bigdecimal` (which depends on `biginteger`).

### Common
The library is available on Jitpack. In order to get it, you have to do as follows.

**1.** Add the Jitpack repository to your project `build.gradle` file.
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

**2.** Add the dependency you prefer. All the dependencies can be used as follows
```groovy
dependencies {
implementation "org.komputing:kbignumbers:$kbignumbers_version"
"com.github.komputing.kbignumbers:{module}-{platform}:{version}"
}
```

### Jvm
Examples:
```groovy
dependencies {
implementation "org.komputing:kbignumbers-jvm:$kbignumbers_version"
"com.github.komputing.kbignumbers:biginteger-common:1.0.0-RC1"
"com.github.komputing.kbignumbers:bigdecimal-jvm:1.0.0-RC1"
}
```
```

### Available modules
| Module | Description |
| :----- | :---------- |
| `biginteger` | Contains the `BigInteger` class definition |
| `bigdecimal` | Contains the `BigDecimal class definition |


### Available platforms
| Platform | Description |
| :------- | :---------- |
| `common` | Kotlin multiplatform |
| `jvm` | JVM-based platform |

### Latest version
The latest version is [![](https://jitpack.io/v/komputing/KBigNumbers.svg)](https://jitpack.io/#komputing/KBigNumbers)

## Current status
### BigInteger
Expand Down
5 changes: 5 additions & 0 deletions bigdecimal/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kotlin.sourceSets {
commonMain.dependencies {
api project(":biginteger")
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kbignumbers.bigdecimal
package org.komputing.kbignumbers.bigdecimal

import kbignumbers.biginteger.BigInteger
import org.komputing.kbignumbers.biginteger.BigInteger

expect class BigDecimal : Number, Comparable<BigDecimal> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kbignumbers.bigdecimal
package org.komputing.kbignumbers.bigdecimal

import kbignumbers.biginteger.BigInteger
import org.komputing.kbignumbers.biginteger.BigInteger

/**
* Immutable arbitrary-precision integers. All operations behave as if
Expand Down Expand Up @@ -303,9 +303,12 @@ actual class BigDecimal(val value: java.math.BigDecimal) : Number(), Comparable<
}

actual companion object {
actual val ZERO: BigDecimal = BigDecimal(java.math.BigDecimal.ZERO)
actual val ONE: BigDecimal = BigDecimal(java.math.BigDecimal.ONE)
actual val TEN: BigDecimal = BigDecimal(java.math.BigDecimal.TEN)
actual val ZERO: BigDecimal =
BigDecimal(java.math.BigDecimal.ZERO)
actual val ONE: BigDecimal =
BigDecimal(java.math.BigDecimal.ONE)
actual val TEN: BigDecimal =
BigDecimal(java.math.BigDecimal.TEN)
actual fun valueOf(value: Long): BigDecimal {
return BigDecimal(java.math.BigDecimal.valueOf(value))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kbignumbers.biginteger
package org.komputing.kbignumbers.biginteger

/**
* Immutable arbitrary-precision integers. All operations behave as if
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kbignumbers.biginteger
package org.komputing.kbignumbers.biginteger

/**
* Immutable arbitrary-precision integers. All operations behave as if
Expand Down Expand Up @@ -73,7 +73,7 @@ package kbignumbers.biginteger
* -2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive) to
* +2<sup>{@code Integer.MAX_VALUE}</sup> (exclusive).
*/
actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<kbignumbers.biginteger.BigInteger> {
actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<BigInteger> {

/**
* Translates the sign-magnitude representation of a BigInteger into a BigInteger.
Expand All @@ -97,7 +97,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @return {@code this + value}
*/
actual fun add(value: BigInteger): BigInteger {
return BigInteger(this.value.add(value.value))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.add(value.value))
}

/**
Expand All @@ -107,7 +107,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @return {@code this - val}
*/
actual fun subtract(value: BigInteger): BigInteger {
return BigInteger(this.value.subtract(value.value))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.subtract(value.value))
}

/**
Expand All @@ -117,7 +117,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @return {@code this * val}
*/
actual fun multiply(value: BigInteger): BigInteger {
return BigInteger(this.value.multiply(value.value))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.multiply(value.value))
}

/**
Expand All @@ -128,7 +128,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @throws ArithmeticException if {@code val} is zero.
*/
actual fun divide(value: BigInteger): BigInteger {
return BigInteger(this.value.divide(value.value))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.divide(value.value))
}

/**
Expand All @@ -142,7 +142,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @see remainder
*/
actual fun mod(m: BigInteger): BigInteger {
return BigInteger(this.value.mod(m.value))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.mod(m.value))
}

/**
Expand All @@ -154,7 +154,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @throws ArithmeticException if {@code val} is zero.
*/
actual fun remainder(value: BigInteger): BigInteger {
return BigInteger(this.value.remainder(value.value))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.remainder(value.value))
}

/**
Expand All @@ -166,7 +166,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @return {@code this ^ val}
*/
actual fun xor(value: BigInteger): BigInteger {
return BigInteger(this.value.xor(value.value))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.xor(value.value))
}

/**
Expand All @@ -178,7 +178,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @return {@code this & val}
*/
actual fun and(value: BigInteger): BigInteger {
return BigInteger(this.value.and(value.value))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.and(value.value))
}

/**
Expand All @@ -192,7 +192,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @see shiftRight
*/
actual fun shiftLeft(n: Int): BigInteger {
return BigInteger(this.value.shiftLeft(n))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.shiftLeft(n))
}

/**
Expand All @@ -206,7 +206,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
* @see shiftLeft
*/
actual fun shiftRight(n: Int): BigInteger {
return BigInteger(this.value.shiftRight(n))
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.shiftRight(n))
}

/**
Expand Down Expand Up @@ -301,11 +301,14 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
}

actual companion object {
actual val ZERO: BigInteger = BigInteger(java.math.BigInteger.ZERO)
actual val ONE: BigInteger = BigInteger(java.math.BigInteger.ONE)
actual val TEN: BigInteger = BigInteger(java.math.BigInteger.TEN)
actual val ZERO: BigInteger =
org.komputing.kbignumbers.biginteger.BigInteger(java.math.BigInteger.ZERO)
actual val ONE: BigInteger =
org.komputing.kbignumbers.biginteger.BigInteger(java.math.BigInteger.ONE)
actual val TEN: BigInteger =
org.komputing.kbignumbers.biginteger.BigInteger(java.math.BigInteger.TEN)
actual fun valueOf(value: Long): BigInteger {
return BigInteger(java.math.BigInteger.valueOf(value))
return org.komputing.kbignumbers.biginteger.BigInteger(java.math.BigInteger.valueOf(value))
}
}
}
13 changes: 12 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ ext.publishLocal = project.hasProperty("publishLocal")
def platforms = ["common", "jvm"]
def projectNeedsPlatform(project, platform) {
def files = project.projectDir.listFiles()
def hasPosix = files.any { it.name == "posix" }
def hasDarwin = files.any { it.name == "darwin" }

if (hasPosix && hasDarwin) return false

if (hasPosix && platform == "darwin") return false
if (hasDarwin && platform == "posix") return false
if (!hasPosix && !hasDarwin && platform == "darwin") return false

return files.any { it.name == "common" || it.name == platform }
}

allprojects {
group = "org.komputing"
group = "com.github.komputing.kbignumbers"
version = configuredVersion
project.ext.hostManager = new HostManager()

Expand All @@ -38,6 +47,8 @@ allprojects {
}

apply plugin: "kotlin-multiplatform"
apply from: rootProject.file("gradle/utility.gradle")

apply plugin: "org.jlleitschuh.gradle.ktlint"

platforms.each { platform ->
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
kotlin.code.style=official

# config
version=1.0.0-RC1
version=0.0.1
kotlin.incremental.multiplatform=true

# gradle
Expand Down
4 changes: 3 additions & 1 deletion gradle/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ kotlin.sourceSets {
api "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
api "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
}
}
}

project.ext.set("commonStructure", true)
31 changes: 31 additions & 0 deletions gradle/darwin.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply from: rootProject.file("gradle/ide.gradle")
apply from: rootProject.file("gradle/native.gradle")

kotlin {
targets {
if (project.ext.ideaActive) {
fromPreset(project.ext.ideaPreset, 'darwin')
} else {
fromPreset(presets.iosArm64, 'iosArm64')
fromPreset(presets.iosArm32, 'iosArm32')
fromPreset(presets.iosX64, 'iosX64')
fromPreset(presets.macosX64, 'macosX64')
}
}
sourceSets {
darwinMain { dependsOn commonMain }
darwinTest

if (!project.ext.ideaActive) {
configure([iosArm32Main, iosArm64Main, iosX64Main, macosX64Main]) {
dependsOn darwinMain
}

configure([iosArm32Test, iosArm64Test, iosX64Test, macosX64Test]) {
dependsOn darwinTest
}
}
}
}

project.ext.set("hasNative", true)
17 changes: 17 additions & 0 deletions gradle/ide.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
task prepareIdeInterop(type: Copy) {
if (project.ext.isLinuxHost) {
from "build/classes/kotlin/linuxX64"
}
if (project.ext.isMacosHost) {
from "build/classes/kotlin/macosX64"
}
if (project.ext.isWinHost) {
from "build/classes/kotlin/mingwX64"
}

into "build/classes/kotlin/posix"
}

configure([assemble]) {
doLast { prepareIdeInterop.execute() }
}
Loading

0 comments on commit 84d02ed

Please sign in to comment.