Skip to content

Coerce integral float and RDF to Integers #2898

@jasongrout

Description

@jasongrout
>  That said, William, is there a reason why this doesn't work?  This is
> >  what is necessitating the two type conversions above.
> >
> >  sage: Integer(float(2))
> >
> > ---------------------------------------------------------------------------
> >  <type 'exceptions.TypeError'>             Traceback (most recent call last)
> >
> >  /home/grout/<ipython console> in <module>()
> >
> >  /home/grout/integer.pyx in sage.rings.integer.Integer.__init__()
> >
> >  <type 'exceptions.TypeError'>: unable to coerce element to an integer
> >
> >
> >  sage: Integer(RDF(2))
> >
> > ---------------------------------------------------------------------------
> >  <type 'exceptions.TypeError'>             Traceback (most recent call last)
> >
> >  /home/grout/<ipython console> in <module>()
> >
> >  /home/grout/integer.pyx in sage.rings.integer.Integer.__init__()
> >
> >  <type 'exceptions.TypeError'>: unable to coerce element to an integer
> >
> >
> >  I guess I would think it was a design decision to not convert floating
> >  points to ints automatically.  However, the following does work:
> >
> >  sage: Integer(RR(2))
> >  2
> >
> >
> >  This seems inconsistent.

Yep.  I think it's just a NotImplementedError.  Please implement it
and post a patch.  Make sure that it only succeeds if

   Integer(k(a)) == a

and otherwise fails.  I.e., Integer(k(a)) should *not* truncate k(a).

William

Component: coercion

Keywords: editor_mhansen

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions