Ticket #1334 (closed defect: fixed)

Opened 5 years ago

Last modified 5 years ago

[with patch, with positive review] Constant polynomial can't be converted to rational

Reported by: robertwb Owned by: dmharvey
Priority: major Milestone: sage-2.8.15
Component: basic arithmetic Keywords:
Cc: Work issues:
Report Upstream: Reviewers:
Authors: Merged in:
Dependencies: Stopgaps:

Description

sage: R.<x> = QQ['x']
sage: QQ(R(1/2))
Traceback (most recent call last):
...
TypeError: Unable to coerce 1/2 (<type 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>) to Rational

Attachments

1334.hg Download (2.6 KB) - added by dmharvey 5 years ago.

Change History

comment:1 Changed 5 years ago by dmharvey

  • Owner changed from somebody to dmharvey
  • Status changed from new to assigned

comment:2 Changed 5 years ago by dmharvey

Fixed it:

sage: R.<x> = QQ['x']
sage: QQ(R(1/2))
1/2

More generally this patch allows coercion of any polynomial to QQ, as long as it's a constant polynomial whose constant term can be coerced into QQ.

Changed 5 years ago by dmharvey

comment:3 Changed 5 years ago by dmharvey

  • Summary changed from Constant polynomial can't be converted to rational to [with patch] Constant polynomial can't be converted to rational

comment:4 Changed 5 years ago by cwitty

  • Summary changed from [with patch] Constant polynomial can't be converted to rational to [with patch, with positive review] Constant polynomial can't be converted to rational

Looks good to me. (doctests pass, code looks good)

comment:5 Changed 5 years ago by mabshoff

  • Status changed from assigned to closed
  • Resolution set to fixed

Merged in 2.8.15.alpha1.

comment:6 Changed 5 years ago by mabshoff

  • Milestone set to sage-2.8.15
Note: See TracTickets for help on using tickets.