Skip to content

Commit 84d02ed

Browse files
RiccardoMligi
authored andcommitted
Project architecture improvements (#2)
* - 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
1 parent fd2e52b commit 84d02ed

File tree

19 files changed

+437
-54
lines changed

19 files changed

+437
-54
lines changed

.ci/kontinuum.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type":"library",
3+
"stages":["build"]
4+
}

README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,53 @@
55
[BigDecimal](https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html).
66

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

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

13-
### Common
13+
The library is available on Jitpack. In order to get it, you have to do as follows.
14+
15+
**1.** Add the Jitpack repository to your project `build.gradle` file.
16+
```groovy
17+
allprojects {
18+
repositories {
19+
...
20+
maven { url 'https://jitpack.io' }
21+
}
22+
}
23+
```
24+
25+
**2.** Add the dependency you prefer. All the dependencies can be used as follows
1426
```groovy
1527
dependencies {
16-
implementation "org.komputing:kbignumbers:$kbignumbers_version"
28+
"com.github.komputing.kbignumbers:{module}-{platform}:{version}"
1729
}
1830
```
1931

20-
### Jvm
32+
Examples:
2133
```groovy
2234
dependencies {
23-
implementation "org.komputing:kbignumbers-jvm:$kbignumbers_version"
35+
"com.github.komputing.kbignumbers:biginteger-common:1.0.0-RC1"
36+
"com.github.komputing.kbignumbers:bigdecimal-jvm:1.0.0-RC1"
2437
}
25-
```
38+
```
39+
40+
### Available modules
41+
| Module | Description |
42+
| :----- | :---------- |
43+
| `biginteger` | Contains the `BigInteger` class definition |
44+
| `bigdecimal` | Contains the `BigDecimal class definition |
45+
46+
47+
### Available platforms
48+
| Platform | Description |
49+
| :------- | :---------- |
50+
| `common` | Kotlin multiplatform |
51+
| `jvm` | JVM-based platform |
52+
53+
### Latest version
54+
The latest version is [![](https://jitpack.io/v/komputing/KBigNumbers.svg)](https://jitpack.io/#komputing/KBigNumbers)
2655

2756
## Current status
2857
### BigInteger

bigdecimal/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kotlin.sourceSets {
2+
commonMain.dependencies {
3+
api project(":biginteger")
4+
}
5+
}

kbignumbers/common/src/kbignumbers/bigdecimal/BigDecimal.kt renamed to bigdecimal/common/src/org/komputing/kbignumbers/bigdecimal/BigDecimal.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package kbignumbers.bigdecimal
1+
package org.komputing.kbignumbers.bigdecimal
22

3-
import kbignumbers.biginteger.BigInteger
3+
import org.komputing.kbignumbers.biginteger.BigInteger
44

55
expect class BigDecimal : Number, Comparable<BigDecimal> {
66

kbignumbers/jvm/src/kbignumbers/bigdecimal/BigDecimal.kt renamed to bigdecimal/jvm/src/org/komputing/kbignumbers/bigdecimal/BigDecimal.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package kbignumbers.bigdecimal
1+
package org.komputing.kbignumbers.bigdecimal
22

3-
import kbignumbers.biginteger.BigInteger
3+
import org.komputing.kbignumbers.biginteger.BigInteger
44

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

305305
actual companion object {
306-
actual val ZERO: BigDecimal = BigDecimal(java.math.BigDecimal.ZERO)
307-
actual val ONE: BigDecimal = BigDecimal(java.math.BigDecimal.ONE)
308-
actual val TEN: BigDecimal = BigDecimal(java.math.BigDecimal.TEN)
306+
actual val ZERO: BigDecimal =
307+
BigDecimal(java.math.BigDecimal.ZERO)
308+
actual val ONE: BigDecimal =
309+
BigDecimal(java.math.BigDecimal.ONE)
310+
actual val TEN: BigDecimal =
311+
BigDecimal(java.math.BigDecimal.TEN)
309312
actual fun valueOf(value: Long): BigDecimal {
310313
return BigDecimal(java.math.BigDecimal.valueOf(value))
311314
}

kbignumbers/common/src/kbignumbers/biginteger/BigInteger.kt renamed to biginteger/common/src/org/komputing/kbignumbers/biginteger/BigInteger.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kbignumbers.biginteger
1+
package org.komputing.kbignumbers.biginteger
22

33
/**
44
* Immutable arbitrary-precision integers. All operations behave as if

kbignumbers/jvm/src/kbignumbers/biginteger/BigInteger.kt renamed to biginteger/jvm/src/org/komputing/kbignumbers/biginteger/BigInteger.kt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kbignumbers.biginteger
1+
package org.komputing.kbignumbers.biginteger
22

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

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

103103
/**
@@ -107,7 +107,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
107107
* @return {@code this - val}
108108
*/
109109
actual fun subtract(value: BigInteger): BigInteger {
110-
return BigInteger(this.value.subtract(value.value))
110+
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.subtract(value.value))
111111
}
112112

113113
/**
@@ -117,7 +117,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
117117
* @return {@code this * val}
118118
*/
119119
actual fun multiply(value: BigInteger): BigInteger {
120-
return BigInteger(this.value.multiply(value.value))
120+
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.multiply(value.value))
121121
}
122122

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

134134
/**
@@ -142,7 +142,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
142142
* @see remainder
143143
*/
144144
actual fun mod(m: BigInteger): BigInteger {
145-
return BigInteger(this.value.mod(m.value))
145+
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.mod(m.value))
146146
}
147147

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

160160
/**
@@ -166,7 +166,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
166166
* @return {@code this ^ val}
167167
*/
168168
actual fun xor(value: BigInteger): BigInteger {
169-
return BigInteger(this.value.xor(value.value))
169+
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.xor(value.value))
170170
}
171171

172172
/**
@@ -178,7 +178,7 @@ actual class BigInteger(val value: java.math.BigInteger) : Number(), Comparable<
178178
* @return {@code this & val}
179179
*/
180180
actual fun and(value: BigInteger): BigInteger {
181-
return BigInteger(this.value.and(value.value))
181+
return org.komputing.kbignumbers.biginteger.BigInteger(this.value.and(value.value))
182182
}
183183

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

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

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

303303
actual companion object {
304-
actual val ZERO: BigInteger = BigInteger(java.math.BigInteger.ZERO)
305-
actual val ONE: BigInteger = BigInteger(java.math.BigInteger.ONE)
306-
actual val TEN: BigInteger = BigInteger(java.math.BigInteger.TEN)
304+
actual val ZERO: BigInteger =
305+
org.komputing.kbignumbers.biginteger.BigInteger(java.math.BigInteger.ZERO)
306+
actual val ONE: BigInteger =
307+
org.komputing.kbignumbers.biginteger.BigInteger(java.math.BigInteger.ONE)
308+
actual val TEN: BigInteger =
309+
org.komputing.kbignumbers.biginteger.BigInteger(java.math.BigInteger.TEN)
307310
actual fun valueOf(value: Long): BigInteger {
308-
return BigInteger(java.math.BigInteger.valueOf(value))
311+
return org.komputing.kbignumbers.biginteger.BigInteger(java.math.BigInteger.valueOf(value))
309312
}
310313
}
311314
}

build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ ext.publishLocal = project.hasProperty("publishLocal")
2323
def platforms = ["common", "jvm"]
2424
def projectNeedsPlatform(project, platform) {
2525
def files = project.projectDir.listFiles()
26+
def hasPosix = files.any { it.name == "posix" }
27+
def hasDarwin = files.any { it.name == "darwin" }
28+
29+
if (hasPosix && hasDarwin) return false
30+
31+
if (hasPosix && platform == "darwin") return false
32+
if (hasDarwin && platform == "posix") return false
33+
if (!hasPosix && !hasDarwin && platform == "darwin") return false
34+
2635
return files.any { it.name == "common" || it.name == platform }
2736
}
2837

2938
allprojects {
30-
group = "org.komputing"
39+
group = "com.github.komputing.kbignumbers"
3140
version = configuredVersion
3241
project.ext.hostManager = new HostManager()
3342

@@ -38,6 +47,8 @@ allprojects {
3847
}
3948

4049
apply plugin: "kotlin-multiplatform"
50+
apply from: rootProject.file("gradle/utility.gradle")
51+
4152
apply plugin: "org.jlleitschuh.gradle.ktlint"
4253

4354
platforms.each { platform ->

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kotlin.code.style=official
33

44
# config
5-
version=1.0.0-RC1
5+
version=0.0.1
66
kotlin.incremental.multiplatform=true
77

88
# gradle

gradle/common.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ kotlin.sourceSets {
66
api "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
77
api "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
88
}
9-
}
9+
}
10+
11+
project.ext.set("commonStructure", true)

0 commit comments

Comments
 (0)