API documentation
HalfIntegers.Half
HalfIntegers.HalfInteger
HalfIntegers.checked_twice
HalfIntegers.half
HalfIntegers.half
HalfIntegers.ishalfinteger
HalfIntegers.ishalfodd
HalfIntegers.onehalf
HalfIntegers.twice
HalfIntegers.twice
Types
HalfIntegers.Half
— TypeHalf{T<:Integer} <: HalfInteger
Type for half-integers $n/2$ where $n$ is of type T
.
Aliases for Half{T}
are defined for all standard Signed
and Unsigned
integer types, so that, e.g., HalfInt
can be used instead of Half{Int}
:
T | Alias for Half{T} |
---|---|
Int | HalfInt |
Int8 | HalfInt8 |
Int16 | HalfInt16 |
Int32 | HalfInt32 |
Int64 | HalfInt64 |
Int128 | HalfInt128 |
BigInt | BigHalfInt (not HalfBigInt !) |
UInt | HalfUInt |
UInt8 | HalfUInt8 |
UInt16 | HalfUInt16 |
UInt32 | HalfUInt32 |
UInt64 | HalfUInt64 |
UInt128 | HalfUInt128 |
HalfIntegers.HalfInteger
— TypeHalfInteger <: Real
Abstract supertype for half-integers. Here, every number $n/2$ where $n\in\mathbb{Z}$ is considered a half-integer, regardless of whether $n$ is even or odd.
Functions
HalfIntegers.checked_twice
— Methodchecked_twice(x)
Calculate 2x
, checking for overflow. (not exported)
This function requires at least HalfIntegers 1.4.
Examples
julia> x = typemax(Int64)
9223372036854775807
julia> twice(x)
-2
julia> HalfIntegers.checked_twice(x)
ERROR: OverflowError: 9223372036854775807 + 9223372036854775807 overflowed for type Int64
Stacktrace:
[...]
HalfIntegers.half
— Methodhalf([T<:Complex{<:HalfInteger},] x)
For a complex value x
with integer real and imaginary parts, return x/2
as a complex number of type T
. If T
is not given, return an appropriate complex number type with half-integer parts. Throw an InexactError
if the real or the imaginary part of x
are not integer.
missing
as an argument requires at least HalfIntegers 1.1.
Examples
julia> half(3 + 2im)
3/2 + 1*im
julia> half(Complex{HalfInt32}, 1.0 + 5.0im)
1/2 + 5/2*im
HalfIntegers.half
— Methodhalf([T<:HalfInteger,] x)
For an integer value x
, return x/2
as a half-integer of type T
. If T
is not given, return an appropriate HalfInteger
type. Throw an InexactError
if x
is not an integer.
missing
as an argument requires at least HalfIntegers 1.1.
Examples
julia> half(3)
3/2
julia> half(-5.0)
-5/2
julia> half(HalfInt16, 8)
4
HalfIntegers.ishalfinteger
— Methodishalfinteger(x)
Test whether x
is numerically equal to some half-integer.
Examples
julia> ishalfinteger(3.5)
true
julia> ishalfinteger(2)
true
julia> ishalfinteger(1//3)
false
HalfIntegers.ishalfodd
— Methodishalfodd(x)
Test whether x
is numerically equal to some half-odd-integer, i.e., a number $n/2$ where $n$ is an odd integer.
Examples
julia> ishalfodd(3.5)
true
julia> ishalfodd(2)
false
julia> ishalfodd(1//3)
false
HalfIntegers.onehalf
— Methodonehalf(x)
Return the value 1/2 in the type of x
(x
can also specify the type itself).
missing
as an argument requires at least HalfIntegers 1.1.
Some abstract types as arguments require at least HalfIntegers 1.2.
Examples
julia> onehalf(7//3)
1//2
julia> onehalf(HalfInt)
1/2
HalfIntegers.twice
— Methodtwice(x)
Return 2x
. If x
is a HalfInteger
, return an appropriate integer type.
missing
as an argument requires at least HalfIntegers 1.1.
Examples
julia> twice(2)
4
julia> twice(1.5)
3.0
julia> twice(HalfInt8(3/2)) # returns an Int8
3
julia> twice(HalfInt32(3.0) + HalfInt32(2.5)*im) # returns a Complex{Int32}
6 + 5im
HalfIntegers.twice
— Methodtwice(T<:Integer, x)
twice(T<:Complex{<:Integer}, x)
Return 2x
as a number of type T
.
missing
as an argument requires at least HalfIntegers 1.1.
Examples
julia> twice(Int16, HalfInt(5/2))
5
julia> twice(Complex{BigInt}, HalfInt(5/2) + HalfInt(3)*im)
5 + 6im