Skip to content

Data type precision problems? #5272

@durack1

Description

@durack1

Hi folks I've just been investigating some type conversion and came across what appears unusual behaviour to me - I would have expected these statements to more faithfully print the values at their respective precisions:

>>> import numpy
>>> numpy.version.version
'1.9.0'
>>> a = numpy.array([3991.86795711963],dtype='float64')
>>> print a
[ 3991.86795712]
>>> print numpy.float32(a)
[ 3991.86791992]
>>> print numpy.float64(a)
3991.86795712 ; # Why does this print statement look different to the above (float32) - no brackets
>>> a = numpy.array([3991.86795711963],dtype='float128')
>>> print numpy.float128(a)
[ 3991.868] ; # Why is this truncated when it should have double the precision of float64?
>>> a
array([ 3991.868], dtype=float128)
>>> numpy.float128(a)
array([ 3991.868], dtype=float128)
>>> print a
[ 3991.868]
>>> print a*1
[ 3991.868]

I haven't investigated playing around with numpy.set_printoptions(precision=2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions