Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JuliaExperimental: incorrect use of AbsInt and GcdInt; create_rational is dangerous #71

Closed
fingolfin opened this issue Oct 11, 2018 · 0 comments
Assignees
Labels
kind: bug Something isn't working

Comments

@fingolfin
Copy link
Member

JuliaExperimental calls AbsInt and GcdInt with rationals as arguments, which cannot work and will lead to crashes and/or corrupt data.

Note there is a kernel function AbsRat which can be used instead of AbsInt. This function is also available on the GAP level as ABS_RAT, so it could also be called as GAP.GAPFuncs.ABS_RAT. However, this may be slower compared to the ccall, see also issue #68 . Another thing one could try is to simply use ccall(:AbsRat, ..., i.e. without setting up a wrapper in gap_macros.c

For GcdInt, it is unclear to me what the intended meaning is when computing the gcd of two rationals. I'd say it is always 1 (and GAP agrees), except of course if both inputs are 0.

Lastly, create_rational is rather dangerous, as it allows creating denormalized rationals, such as 2/1, 8/4, 3/0 or 2/-1. GAP is not prepared for this -- it expects rationals to always have a denominator > 1. If that rules is violated, then e.g. the rational 2/1 in GAP is not equal to the integer 2.

I suggest to instead call the GAP kernel function QuoRat, which accepts both rationals and integers as arguments.

Lastly, with the current master branch, the wrapper functions MyFuncLT in the kernel are no longer necessary, as LT etc. all were converted from macros into functions.

@fingolfin fingolfin added the kind: bug Something isn't working label Nov 1, 2018
fingolfin added a commit to fingolfin/GAP.jl that referenced this issue Nov 13, 2018
This code is not needed anymore due the existence of the convenience wrappers
for arithmetic operations on GAP objects in Julia, resp. on Julia objects in
GAP.

Moreover, this code was buggy; and was not yet converted to use
`ForeignGAP.MPtr` (leading to GC crash). All in all, it seems best to
"conclude" this experiment by removing it.

Resolves oscar-system#71
fingolfin added a commit that referenced this issue Nov 13, 2018
This code is not needed anymore due the existence of the convenience wrappers
for arithmetic operations on GAP objects in Julia, resp. on Julia objects in
GAP.

Moreover, this code was buggy; and was not yet converted to use
`ForeignGAP.MPtr` (leading to GC crash). All in all, it seems best to
"conclude" this experiment by removing it.

Resolves #71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants