-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #389 from oscar-system/PolyhedralGeometry/scalar-t…
…ypes
- Loading branch information
Showing
16 changed files
with
464 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const qe_suppT = Union{Polymake.Rational} | ||
|
||
QuadraticExtension{T}(a::Number, b::Number, r::Number) where T<:qe_suppT = | ||
QuadraticExtension{T}(convert(T, a), convert(T, b), convert(T, r)) | ||
|
||
QuadraticExtension{T}(a::Number) where T<:qe_suppT = QuadraticExtension{T}(a, 0, 0) | ||
|
||
QuadraticExtension(x...) = QuadraticExtension{Rational}(x...) | ||
|
||
Base.zero(::Type{<:QuadraticExtension{T}}) where T<:qe_suppT = QuadraticExtension{T}(0) | ||
Base.zero(::QuadraticExtension{T}) where T<:qe_suppT = QuadraticExtension{T}(0) | ||
Base.one(::Type{<:QuadraticExtension{T}}) where T<:qe_suppT = QuadraticExtension{T}(1) | ||
Base.one(::QuadraticExtension{T}) where T<:qe_suppT = QuadraticExtension{T}(1) | ||
|
||
generating_field_elements(qe::QuadraticExtension{T}) where T<:qe_suppT = (a = _a(qe), b = _b(qe), r =_r(qe)) | ||
|
||
# we might need to split this up | ||
# if we should wrap `QuadraticExtension` with another scalar than `Rational` | ||
function Base.promote_rule(::Type{<:QuadraticExtension{T}}, | ||
::Type{<:Union{T, Base.Integer, Base.Rational{<:Base.Integer}}}) where T<:qe_suppT | ||
return QuadraticExtension{T} | ||
end | ||
|
||
import Base: <, //, <= | ||
# defining for `Real` to avoid disambiguities | ||
Base.:<(x::Real, y::QuadraticExtension{T}) where T<:qe_suppT = convert(QuadraticExtension{T}, x) < y | ||
Base.:<(x::QuadraticExtension{T}, y::Real) where T<:qe_suppT = x < convert(QuadraticExtension{T}, y) | ||
Base.://(x::Real, y::QuadraticExtension{T}) where T<:qe_suppT = convert(QuadraticExtension{T}, x) // y | ||
Base.://(x::QuadraticExtension{T}, y::Real) where T<:qe_suppT = x // convert(QuadraticExtension{T}, y) | ||
|
||
Base.:<=(x::QuadraticExtension{T}, y::QuadraticExtension{T}) where T<:qe_suppT = x < y || x == y | ||
Base.:/(x::QuadraticExtension{T}, y::QuadraticExtension{T}) where T<:qe_suppT = x // y | ||
|
||
# no-copy convert | ||
convert(::Type{<:QuadraticExtension{T}}, qe::QuadraticExtension{T}) where T<:qe_suppT = qe | ||
|
||
function convert(to::Type{<:Number}, qe::QuadraticExtension) | ||
!iszero(_b(qe)) && !iszero(_r(qe)) && throw(DomainError("Given QuadraticExtension not trivial.")) | ||
return convert(to, _a(qe)) | ||
end | ||
|
||
# compatibility with Float64 | ||
Float64(x::QuadraticExtension{T}) where T<:qe_suppT = Float64(_a(x)) + Float64(_b(x)) * sqrt(Float64(_r(x))) | ||
Base.promote_rule(::Type{<:QuadraticExtension{Rational}}, ::Type{<:AbstractFloat}) = Float64 | ||
|
||
convert(to::Type{<:AbstractFloat}, qe::QuadraticExtension) = convert(to, Float64(qe)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f4972bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator: register()
f4972bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/54585
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: