mirror of
https://github.com/tgorordo/WignerSymbols.jl.git
synced 2026-06-13 02:02:14 -07:00
update HalfInteger
This commit is contained in:
parent
8854cfbb97
commit
39bbd0ced8
2 changed files with 38 additions and 3 deletions
|
|
@ -21,11 +21,18 @@ function Base.convert(::Type{HalfInteger}, r::Rational)
|
|||
elseif r.den == 2
|
||||
return HalfInteger(r.num)
|
||||
else
|
||||
throw(InexactError())
|
||||
throw(InexactError(:HalfInteger, HalfInteger, r))
|
||||
end
|
||||
end
|
||||
Base.convert(::Type{HalfInteger}, r::Real) = convert(HalfInteger, convert(Rational, r))
|
||||
Base.convert(T::Type{<:Integer}, s::HalfInteger) = iseven(s.num) ? convert(T, s.num>>1) : throw(InexactError())
|
||||
function Base.convert(::Type{HalfInteger}, r::Real)
|
||||
num = 2*r
|
||||
if isinteger(num)
|
||||
return HalfInteger(convert(Int, num))
|
||||
else
|
||||
throw(InexactError(:HalfInteger, HalfInteger, r))
|
||||
end
|
||||
end
|
||||
Base.convert(T::Type{<:Integer}, s::HalfInteger) = iseven(s.num) ? convert(T, s.num>>1) : throw(InexactError(Symbol(T), T, s))
|
||||
Base.convert(T::Type{<:Rational}, s::HalfInteger) = convert(T, s.num//2)
|
||||
Base.convert(T::Type{<:Real}, s::HalfInteger) = convert(T, s.num/2)
|
||||
Base.convert(::Type{HalfInteger}, s::HalfInteger) = s
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue