Skip to content

sage_input is unreliable for elements of ComplexField #32129

@mwageringel

Description

@mwageringel
sage: fld = ComplexField(200)
sage: a = fld('0.85425665148473689034386458431097348561089439860408577398333', '20')
sage: sage_input(a, verify=True)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
...
AssertionError: Expected 0.85425665148473689034386458431097348561089439860408577398333 + 20.000000000000000000000000000000000000000000000000000000000*I == 0.85425665148473689034386458431097348561089439860408577398333 + 20.000000000000000000000000000000000000000000000000000000000*I

Apparently, the last bits that are usually not printed get lost.

sage: b = sage_eval(sage_input(a, verify=False))
sage: a == b  # should be True
False
sage: a.str(truncate=False)
0.85425665148473689034386458431097348561089439860408577398333000 + 20.000000000000000000000000000000000000000000000000000000000000*I
sage: b.str(truncate=False)
0.85425665148473689034386458431097348561089439860408577398333374 + 20.000000000000000000000000000000000000000000000000000000000000*I

This was found by

sage -t --long --random-seed=3159 src/sage/rings/complex_mpfr.pyx

The corresponding real version works:

sage: sage_input(a.real(), verify=True)
# Verified
RealField(200)(0.85425665148473689034386458431097348561089439860408577398333)

In #29979, a doctest was marked not tested because of this.

Component: numerical

Reviewer: Markus Wageringel

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions