Skip to content

Loss of precision with np.str_ input to np.longdouble #15608

@mhvk

Description

@mhvk

While trying to debug issues in a pulsar timing package, a very odd bug appeared:

import numpy as np
mjd = '50000.012345678901234'
np.longdouble(mjd)
# 50000.012345678901234
np.longdouble(np.str_(mjd))
# 50000.0123456789006
np.str_(mjd)
# '50000.012345678901234'

So, apparently python string and numpy string get converted differently...

p.s. Extends as expected to array/astype:

np.array([mjd, mjd], dtype='f16')[0]
# 50000.012345678901234
np.array([mjd, mjd]).astype('f16')[0]
# 50000.0123456789006

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions