Skip to content

spurious cast of floating-point literal to 53 bits #34832

Open
@zimmermann6

Description

@zimmermann6

Consider the following two functions:

def foo():
   R.<x> = RealField(256)[]
   p = 1 + 0.5 * x^2 + 0.99999999999999999999999999999999999999999999999999999999999999999997189189208487731170453344442892098480527126967523049592569694449765629104157488759641776 * x
   print (p)

def bar():
   R.<x> = RealField(256)[]
   p = 1 + 1/2 * x^2 + 0.99999999999999999999999999999999999999999999999999999999999999999997189189208487731170453344442892098480527126967523049592569694449765629104157488759641776 * x
   print (p)

They give in Sage 9.7:

sage: foo()
0.500000000000000*x^2 + x + 1.00000000000000
sage: bar()
0.5000000000000000000000000000000000000000000000000000000000000000000000000000*x^2 + 0.9999999999999999999999999999999999999999999999999999999999999999999718918921*x + 1.000000000000000000000000000000000000000000000000000000000000000000000000000

In the first one, Sage decided to cast all floating-point literals to 53 bits, descpite 0.5 is exact on 256 bits.

Component: basic arithmetic

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

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