Partially revamp the HalfInteger type (#4)

* Call the HalfInteger field twofold

Makes it more immediately obvious what the meaning of the value stored
in the field is.

* Introduce new constructors for HalfInteger

The primary inner constructor mirrors the two-argument constructor of
the Rational type, where the user provides the numerator and denominator
values.

There is also a single argument outer constructor that makes HalfInteger
behave like a normal numeric type such that HalfInteger(n) == n.

* Move HalfInteger tests to a separate file

The using statements in halfinteger.jl are there so that it would be
possible to run the file separately from the other tests.

* Test the single-argument HalfInteger constructor

* Organize halfinteger.jl a bit

Prioritise the convert methods.

* Add multiplication with integer to HalfInteger

* Implement parsing and printing for HalfInteger

* parse(::HalfInteger, x) method
* Overload show to pretty-print HalfInteger

* Overload Base.numerator/denominator

And add tests for the other supplementary functions and methods as
well.

* Add HalfIntegerRange type

Can be constructed using the range operator :. Currently only supports
unit steps in the positive direction.

* Address feedback

* Rename .twofold -> .numerator
* Consistent variable names
* Remove unnecessary methods for HalfIntegerRange

* Allow constructing HalfIntegerRange with non-integer difference

* Add docs and ceil(::HalfInteger)
This commit is contained in:
Morten Piibeleht 2019-01-11 09:50:46 +13:00 committed by Jutho
parent 80038db6a3
commit 8ebb2c791b
4 changed files with 341 additions and 46 deletions

View file

@ -27,6 +27,9 @@ While the following function signatures are probably self-explanatory, you can q
* `δ(j₁, j₂, j₃) -> ::Bool`
* `Δ(T::Type{<:AbstractFloat} = Float64, j₁, j₂, j₃) -> ::T`
The package also defines the `HalfInteger` type that can be used to represent half-integer values.
Furthermore, the range operator `a:b` can be used to create ranges of `HalfInteger` values (a `HalfIntegerRange`).
## Implementation
Largely based on reading the paper (but not the code):