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

Inconsistency in integer quotient #2579

Closed
rishikesha mannequin opened this issue Mar 18, 2008 · 9 comments
Closed

Inconsistency in integer quotient #2579

rishikesha mannequin opened this issue Mar 18, 2008 · 9 comments

Comments

@rishikesha
Copy link
Mannequin

rishikesha mannequin commented Mar 18, 2008

sage: a=-17
sage: a//4
-5
sage: a.div(4)
-4
sage: a.mod(4)
3

I recommend we redefine

def div(self, other):
    q,_ = self.quo_rem(other)
    return q

Component: basic arithmetic

Issue created by migration from https://trac.sagemath.org/ticket/2579

@rishikesha rishikesha mannequin added this to the sage-2.11 milestone Mar 18, 2008
@rishikesha
Copy link
Mannequin Author

rishikesha mannequin commented Mar 18, 2008

comment:1

sage: a=-17

sage: a//4

-5

sage: a.div(4)

-4

sage: a.mod(4)

3

I recommend we redefine

def div(self, other):

q,_ = self.quo_rem(other) 

return q

@sagetrac-mabshoff

This comment has been minimized.

@sagetrac-cwitty
Copy link
Mannequin

sagetrac-cwitty mannequin commented Mar 18, 2008

comment:3

If we want a.div(b) to be floor(a/b) (which I agree we probably do, if we want the method to exist at all), the correct fix is to change from mpz_tdiv_qr to mpz_fdiv_q.

@rishikesha
Copy link
Mannequin Author

rishikesha mannequin commented Mar 18, 2008

I think the basis logic should be as below. Since this will make the remainder always positive.

if mpz_sgn(_other.value) == 1:
            mpz_fdiv_q(q.value, _self.value, _other.value)        
else:
            mpz_cdiv_q(q.value, _self.value, _other.value)

@rishikesha
Copy link
Mannequin Author

rishikesha mannequin commented Mar 19, 2008

Attachment: integerdiv.patch.gz

@rishikesha
Copy link
Mannequin Author

rishikesha mannequin commented Mar 19, 2008

comment:5

I used quo_rem to redefine div. I would have essentially copied and pasted quo_rem otherwise.

@mwhansen
Copy link
Contributor

comment:6

Looks good to me.

@sagetrac-mabshoff

This comment has been minimized.

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Mar 20, 2008

comment:8

Merged in Sage 2.11.alpha0

@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Mar 20, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant