Skip to content

Commit

Permalink
Merge pull request #468 from oscar-system/bl/ontypes
Browse files Browse the repository at this point in the history
OscarNumber: small improvements
  • Loading branch information
benlorenz authored Feb 1, 2024
2 parents 4a5f80d + b06e500 commit a537177
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Polymake"
uuid = "d720cf60-89b5-51f5-aff5-213f193123e7"
repo = "https://github.com/oscar-system/Polymake.jl.git"
version = "0.11.11"
version = "0.11.12"

[deps]
BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f"
Expand Down
21 changes: 9 additions & 12 deletions src/oscarnumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ end
end
end

_on_cmp_int(e1::T, e2::T) where T = Clong(Base.cmp(e1, e2))
@generated _on_gen_cmp(::Type{ArgT}) where ArgT =
quote
@cfunction(Base.cmp, Clong, (Ref{ArgT}, Ref{ArgT}))
@cfunction(_on_cmp_int, Clong, (Ref{ArgT}, Ref{ArgT}))
end

@generated _on_gen_is_zero(::Type{ArgT}) where ArgT =
Expand All @@ -130,16 +131,13 @@ end
@cfunction(Base.isone, Bool, (Ref{ArgT},))
end

_on_sign_int(e::T) where T = Base.cmp(e,0)::Int
_on_sign_int(e::T) where T = Clong(Base.cmp(e,0))
@generated _on_gen_sign_int(::Type{ArgT}) where ArgT =
quote
@cfunction(_on_sign_int, Clong, (Ref{ArgT},))
end

function _fieldelem_to_float(e::T) where T
if !hasmethod(Float64, Tuple{T})
error("OscarNumber: cannot coerce to Float64, please define 'Polymake._fieldelem_to_float(e::$T)::Float64'")
end
return Float64(e)
end

Expand All @@ -153,9 +151,6 @@ end
end

function _fieldelem_to_rational(e::T) where T
if !hasmethod(Rational{BigInt}, Tuple{T})
error("OscarNumber: cannot check is_rational, please define 'Polymake._fieldelem_to_rational(e::$T)::Rational{BigInt}'")
end
Polymake._fieldelem_is_rational(e) || error("not a rational number")
return Base.Rational{BigInt}(e)
end
Expand Down Expand Up @@ -204,10 +199,14 @@ end
@cfunction(_on_init, Ref{ArgT}, (Clong, Ptr{ArgT}, Clong))
end

function _fieldelem_from_rational(f::Any, r::Base.Rational{BigInt})
return f(r)
end

function _on_init_frac(id::Clong, ::Ptr{ArgT}, np::Ptr{BigInt}, dp::Ptr{BigInt})::ArgT where ArgT
n = unsafe_load(np)::BigInt
d = unsafe_load(dp)::BigInt
return _on_parent_by_id[id](Base.Rational{BigInt}(n, d))
return _fieldelem_from_rational(_on_parent_by_id[id], Base.Rational{BigInt}(n, d))::ArgT
end
@generated _on_gen_init_frac(::Type{ArgT}) where ArgT =
quote
Expand Down Expand Up @@ -277,9 +276,7 @@ function register_julia_element(e, p, t::Type)
error("OscarNumber: immutable julia types not supported")
end

for type in (Int64, Base.Rational{BigInt})
hasmethod(p, (type,)) || error("OscarNumber: no constructor ($p)($type)")
end
hasmethod(p, (Int64,)) || error("OscarNumber: no constructor ($p)(Int64)")

dispatch = oscar_number_dispatch_helper()
dispatch.index = newid
Expand Down

2 comments on commit a537177

@benlorenz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

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/100012

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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:

git tag -a v0.11.12 -m "<description of version>" a537177f2625d4872e14820f88b9e13d3d179cad
git push origin v0.11.12

Please sign in to comment.