Opened 3 years ago

Closed 2 years ago

## #28394 closed defect (fixed)

# comparison of sage rationals with gmpy2 mpq broken

Reported by: | Vincent Delecroix | Owned by: | |
---|---|---|---|

Priority: | major | Milestone: | sage-9.2 |

Component: | basic arithmetic | Keywords: | |

Cc: | vklein | Merged in: | |

Authors: | Vincent Delecroix | Reviewers: | Matthias Koeppe |

Report Upstream: | Fixed upstream, in a later stable release. | Work issues: | |

Branch: | 21d07f6 (Commits, GitHub, GitLab) | Commit: | 21d07f652037874491cfa08dc569d10a30285084 |

Dependencies: | #30583 | Stopgaps: |

### Description (last modified by )

sage: import gmpy2 sage: gmpy2.mpq(5,3) == 5/3 --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-2-7445d1641afe> in <module>() ----> 1 gmpy2.mpq(Integer(5),Integer(3)) == Integer(5)/Integer(3) TypeError: cannot convert object to mpq sage: 5/3 == gmpy2.mpq(5,3) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-3-593205bfa17f> in <module>() ----> 1 Integer(5)/Integer(3) == gmpy2.mpq(Integer(5),Integer(3)) /opt/sage/sage-py3-gcc/local/lib/python3.7/site-packages/sage/rings/rational.pyx in sage.rings.rational.Rational.__richcmp__ (build/cythonized/sage/rings/rational.c:9498)() 868 c = mpq_cmp_si((<Rational>left).value, PyInt_AS_LONG(right), 1) 869 else: --> 870 return coercion_model.richcmp(left, right, op) 871 872 return rich_to_bool_sgn(op, c) /opt/sage/sage-py3-gcc/local/lib/python3.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.richcmp (build/cythonized/sage/structure/coerce.c:19779)() 1946 # we would end up trying the same coercion again. 1947 if not y_is_Element and Py_TYPE(y).tp_richcompare: -> 1948 res = Py_TYPE(y).tp_richcompare(y, x, revop(op)) 1949 if res is not NotImplemented: 1950 return res TypeError: cannot convert object to mpq

Sage integers are perfectly fine

sage: gmpy2.mpz(3) == 3 True sage: 3 == gmpy2.mpz(3) True

gmpy2's issue #251

### Change History (14)

### comment:1 Changed 3 years ago by

### comment:2 Changed 3 years ago by

Description: | modified (diff) |
---|---|

Report Upstream: | N/A → Reported upstream. No feedback yet. |

### comment:3 Changed 3 years ago by

Report Upstream: | Reported upstream. No feedback yet. → Fixed upstream, in a later stable release. |
---|

### comment:4 Changed 3 years ago by

Do you think this need a patch ?

IMHO it's not necessary. You can call `__mpq__`

explicitly if needed :

sage: from gmpy2 import mpq sage: q = 5/3 sage: q.__mpq__() == mpq(5,3) True sage: mpq(q) == mpq(5,3) True

### comment:6 Changed 3 years ago by

Milestone: | sage-8.9 → sage-9.1 |
---|

Ticket retargeted after milestone closed

### comment:7 Changed 2 years ago by

Milestone: | sage-9.1 → sage-9.2 |
---|

Moving tickets to milestone sage-9.2 based on a review of last modification date, branch status, and severity.

### comment:8 Changed 2 years ago by

Why `TypeError: cannot convert object to mpq`

if converting is as simple as `mpq(5/3)`

?

### comment:9 Changed 2 years ago by

This has been fixed upstream

sage: gmpy2.mpq(5,3) == 5/3 True sage: 5/3 == gmpy2.mpq(5,3) True

EDIT: in version 2.1.0b4

### comment:10 Changed 2 years ago by

Dependencies: | → #30583 |
---|

### comment:11 Changed 2 years ago by

Authors: | → Vincent Delecroix |
---|---|

Branch: | → u/vdelecroix/28394 |

Commit: | → 0e5d1f3f9992bd9396eda3e79b479a1e80140bcd |

Status: | new → needs_review |

### comment:12 Changed 2 years ago by

Branch: | u/vdelecroix/28394 → u/mkoeppe/28394 |
---|

### comment:13 Changed 2 years ago by

Commit: | 0e5d1f3f9992bd9396eda3e79b479a1e80140bcd → 21d07f652037874491cfa08dc569d10a30285084 |
---|---|

Reviewers: | → Matthias Koeppe |

Status: | needs_review → positive_review |

### comment:14 Changed 2 years ago by

Branch: | u/mkoeppe/28394 → 21d07f652037874491cfa08dc569d10a30285084 |
---|---|

Resolution: | → fixed |

Status: | positive_review → closed |

**Note:**See TracTickets for help on using tickets.

It looks likes it's a gmpy2 bug.