55# Kotlin Rational
66
77[ ![ build] ( https://github.com/binkley/kotlin-rational/workflows/build/badge.svg )] ( https://github.com/binkley/kotlin-rational/actions )
8+ [ ![ jitpack] ( https://img.shields.io/jitpack/v/github/binkley/kotlin-rational )] ( https://jitpack.io/#binkley/kotlin-rational )
9+ [ ![ tag] ( https://img.shields.io/github/v/tag/binkley/kotlin-rational )] ( https://github.com/binkley/kotlin-rational/tags )
810[ ![ issues] ( https://img.shields.io/github/issues/binkley/kotlin-rational.svg )] ( https://github.com/binkley/kotlin-rational/issues/ )
911[ ![ Public Domain] ( https://img.shields.io/badge/license-Public%20Domain-blue.svg )] ( http://unlicense.org/ )
1012[ ![ made with Kotlin] ( https://img.shields.io/badge/made%20with-Kotlin-1f425f.svg )] ( https://kotlinlang.org/ )
@@ -35,19 +37,135 @@ To build, use `./mvnw clean verify`.
3537
3638Try ` ./run.sh ` for a demonstration.
3739
38- There are no run-time dependencies.
40+ There are no run-time dependencies beyond the Kotlin standard library.
41+
42+ To build as CI would, use ` ./batect build ` .
43+
44+ Try ` ./batect run ` for a demonstration as CI would (were it interested).
45+
46+ This code builds and passes tests and checks on JDK 11, 13, 14, and 15.
47+
48+ ---
49+
50+ ## TOC
51+
52+ * [ Releases] ( #releases )
53+ * [ Use] ( #use )
54+ * [ API] ( #api )
55+ * [ Build] ( #build )
56+ * [ Design choices] ( #design-choices )
57+ * [ Implementation choices] ( #implementation-choices )
58+ * [ Further reading] ( #further-reading )
59+
60+ ---
3961
4062## Releases
4163
42- * [ 2.0.0-SNAPSHOT ] ( https://github.com/binkley/kotlin-rational/tree/master )
43- &mdash ; (2020-11-26) In progress / Rationalized type and package names
64+ * [ 2.0.0] ( https://github.com/binkley/kotlin-rational/tree/kotlin-rational-2.0.0 )
65+ &mdash ; (2020-11-26) Rationalized type and package names, refreshed site
4466* [ 1.0.0] ( https://github.com/binkley/kotlin-rational/tree/kotlin-rational-1.0.0 )
4567 &mdash ; (2020-04-02) Initial prototype released for reuse by
4668 [ KUnits] ( https://github.com/binkley/kunits )
4769
48- ## Platform
70+ ---
71+
72+ ## Use
73+
74+ ### Gradle
75+
76+ This snippet uses Kotlin syntax for the build script:
77+
78+ ``` kotlin
79+ repositories {
80+ maven {
81+ url = uri(" https://jitpack.io" )
82+ }
83+ }
84+
85+ dependencies {
86+ implementation(" com.github.binkley:kotlin-rational:2.0.0" )
87+ }
88+ ```
89+
90+ ### Maven
91+
92+ This snippet is an elided ` pom.xml ` :
93+
94+ ``` xml
95+
96+ <project >
97+ <dependencies >
98+ <dependency >
99+ <groupId >com.github.binkley</groupId >
100+ <artifactId >kotlin-rational</artifactId >
101+ <version >2.0.0</version >
102+ </dependency >
103+ </dependencies >
49104
50- This code has been built and passes tests on JDK 11, 13, and 14.
105+ <repositories >
106+ <repository >
107+ <id >jitpack.io</id >
108+ <url >https://jitpack.io</url >
109+ </repository >
110+ </repositories >
111+ </project >
112+ ```
113+
114+ ---
115+
116+ ## API
117+
118+ In general, when properties, methods, and operations do not have
119+ documentation, they behave similarly as their floating-point counterpart.
120+
121+ ### Constructors
122+
123+ All constructors are _ private_ . Please use:
124+
125+ - ` over ` infix operators, _ eg_ , ` 2 over 1 `
126+ - ` valueOf ` companion methods, _ eg_ ,
127+ ` BigRational.valueOf(BigInteger.TWO, BigInteger.ONE) `
128+
129+ ### Properties
130+
131+ - ` numerator ` , ` denominator ` , ` absoluteValue ` , ` sign ` , and ` reciprocal `
132+ behave as expected
133+
134+ ### Methods
135+
136+ - ` isNaN() ` , ` isPositiveInfinity() ` , ` isNegativeInfinity() `
137+ - ` isFinite() ` , ` isInfinite() ` . Note than ` NaN ` is neither finite nor infinite
138+ - ` isInteger() ` , ` isDyadic() ` (See
139+ [ _ Dyadic rational_ ] ( https://en.wikipedia.org/wiki/Dyadic_rational ) ),
140+ ` isPAdic(p) ` (See
141+ [ _ p_ -adic number] ( https://en.wikipedia.org/wiki/P-adic_number ) )
142+ - ` unaryDiv() ` is a synonym for ` reciprocal ` as a pseudo-operator
143+ - ` gcm(other) ` , ` lcd(other) ` , ` mediant(other) `
144+ - ` toContinuedFraction() `
145+ - ` pow(exponent) `
146+ - ` divideAndRemainder(other) `
147+ - ` floor() ` rounds upwards; ` ceil() ` rounds downwards
148+ - ` truncateAndFraction() ` truncates and provides the truncation and remaining
149+ fraction; ` truncate() ` rounds towards 0; ` fraction() ` provides the remaining
150+ fraction
151+
152+ ### Operators
153+
154+ - All numeric operators (binary and unary ` plus ` and ` minus ` , ` times ` , ` div ` ,
155+ and ` rem ` )
156+ - ` rem ` always returns ` ZERO ` or a non-finite value (rational division is
157+ exact with no remainder)
158+ - Ranges and progressions
159+ - See also ` divideAndRemainder `
160+
161+ ### Types
162+
163+ This code attempts to ease programmer typing through overloading. Where
164+ sensible, if a ` FloatingBigRational ` and ` FixedBigRational ` are provided as
165+ argument or extension method types, then so are ` BigDecimal ` , ` Double ` ,
166+ ` Float ` , ` BigInteger ` , ` Long ` , and ` Int ` .
167+
168+ ---
51169
52170## Build
53171
@@ -71,6 +189,8 @@ Docker container.
71189This shares Maven plugin and dependency downloads with the Docker container
72190run by Batect.
73191
192+ ---
193+
74194## Design choices
75195
76196### Two choices
@@ -101,8 +221,7 @@ These were great help:
101221 mathematical properties of ℚ, the field of the rationals
102222
103223The code for ` FloatingBigRational ` extends ℚ, the field of rational numbers,
104- with
105- [ division by zero] ( https://en.wikipedia.org/wiki/Division_by_zero ) ,
224+ with [ division by zero] ( https://en.wikipedia.org/wiki/Division_by_zero ) ,
106225"not a number", -∞, and +∞, following the lead of
107226[ IEEE 754] ( https://en.wikipedia.org/wiki/IEEE_754 ) , and using the
108227_ affinely extended real line_ as a model. However, this code does not
@@ -182,11 +301,11 @@ This code supports conversion among `Double` and `Float`, and
182301` FloatingBigRational ` and ` FixedBigRational ` for all finite values, and
183302non-finite values for ` FloatingBigRational ` . The conversion is _ exact_ : it
184303constructs a power-of-2 rational value following IEEE 754; so reconverting
185- returns the original floating point value, and for ` FloatingBigRational `
304+ returns the original floating- point value, and for ` FloatingBigRational `
186305converts non-finite values to their corresponding values (for
187306` FixedBigRational ` this raises ` ArithmeticException ` ).
188307
189- | Floating point| ` FloatingBigRational ` | ` FixedBigRational ` |
308+ | floating- point| ` FloatingBigRational ` | ` FixedBigRational ` |
190309| ---| ---| ---|
191310| ` 0.0 ` | ` ZERO ` | ` ZERO ` |
192311| ` NaN ` | ` NaN ` | Raises exception|
@@ -201,12 +320,12 @@ When narrowing types, conversion may lose magnitude, precision, and/or sign
201320
202321There are two ways to handle division by 0:
203322
204- - Produce a ` NaN ` , what floating point numbers do (_ eg_ , ` 1.0 / 0 ` )
323+ - Produce a ` NaN ` , what floating- point numbers do (_ eg_ , ` 1.0 / 0 ` )
205324 (` FloatingBigRational ` )
206325- Raise an error, what fixed point numbers do (_ eg_ , ` 1 / 0 ` )
207326 (` FixedBigRational ` )
208327
209- For ` FloatingBigRational ` , as with floating point, ` NaN != NaN ` , and finite
328+ For ` FloatingBigRational ` , as with floating- point, ` NaN != NaN ` , and finite
210329values equal themselves. As with mathematics, infinities are not equal to
211330themselves, so ` POSITIVE_INFINITY != POSITIVE_INFINTY ` and
212331` NEGATIVE_INFINITY != NEGATIVE_INFINITY ` . (` FloatingBigRational ` does not
@@ -253,60 +372,10 @@ sort, regardless of other values. There is no sense of natural order for
253372` NaN ` , so this code chooses to sort ` NaN ` the same as does ` Double ` .
254373
255374For ` FloatingBigRational ` , all ` NaN ` are "quiet"; none are "signaling",
256- including sorting. This follows the Java convention for floating point, and is
375+ including sorting. This follows the Java convention for floating- point, and is
257376a complex area. (See [ ` NaN ` ] ( https://en.wikipedia.org/wiki/NaN ) .)
258377
259- ## API
260-
261- In general, when properties, methods, and operations do not have
262- documentation, they behave similarly as their floating point counterpart.
263-
264- ### Constructors
265-
266- All constructors are _ private_ . Please use:
267-
268- - ` over ` infix operators, _ eg_ , ` 2 over 1 `
269- - ` valueOf ` companion methods, _ eg_ ,
270- ` BigRational.valueOf(BigInteger.TWO, BigInteger.ONE) `
271-
272- ### Properties
273-
274- - ` numerator ` , ` denominator ` , ` absoluteValue ` , ` sign ` , and ` reciprocal `
275- behave as expected
276-
277- ### Methods
278-
279- - ` isNaN() ` , ` isPositiveInfinity() ` , ` isNegativeInfinity() `
280- - ` isFinite() ` , ` isInfinite() ` . Note than ` NaN ` is neither finite nor infinite
281- - ` isInteger() ` , ` isDyadic() ` (See
282- [ _ Dyadic rational_ ] ( https://en.wikipedia.org/wiki/Dyadic_rational ) ),
283- ` isPAdic(p) ` (See
284- [ _ p_ -adic number] ( https://en.wikipedia.org/wiki/P-adic_number ) )
285- - ` unaryDiv() ` is a synonym for ` reciprocal ` as a pseudo-operator
286- - ` gcm(other) ` , ` lcd(other) ` , ` mediant(other) `
287- - ` toContinuedFraction() `
288- - ` pow(exponent) `
289- - ` divideAndRemainder(other) `
290- - ` floor() ` rounds upwards; ` ceil() ` rounds downwards
291- - ` truncateAndFraction() ` truncates and provides the truncation and remaining
292- fraction; ` truncate() ` rounds towards 0; ` fraction() ` provides the remaining
293- fraction
294-
295- ### Operators
296-
297- - All numeric operators (binary and unary ` plus ` and ` minus ` , ` times ` , ` div ` ,
298- and ` rem ` )
299- - ` rem ` always returns ` ZERO ` or a non-finite value (rational division is
300- exact with no remainder)
301- - Ranges and progressions
302- - See also ` divideAndRemainder `
303-
304- ### Types
305-
306- This code attempts to ease programmer typing through overloading. Where
307- sensible, if a ` FloatingBigRational ` and ` FixedBigRational ` are provided as
308- argument or extension method types, then so are ` BigDecimal ` , ` Double ` ,
309- ` Float ` , ` BigInteger ` , ` Long ` , and ` Int ` .
378+ ---
310379
311380## Implementation choices
312381
@@ -379,6 +448,8 @@ fractions for computing square roots of rationals. A function signature might
379448look like ` FixedBigRational.sqrt(n: Int): FixedContinuedFraction ` to meet
380449restriction 2.
381450
451+ ---
452+
382453## Further reading
383454
384455- [ _ Wheel of
0 commit comments