Tensor print precision

I find the below behavior in both Windows and Linux under version 0.4.1

torch.set_printoptions(precision=20)
torch.tensor([123456789.])
>>> tensor([ 123456792.])

Likewise:

torch.set_printoptions(precision=20)
x = torch.FloatTensor([1.23423424578349539453434])
print(x,x.data)
>>> tensor([1.23423421382904052734]) tensor([1.23423421382904052734])

I understand that this has been addressed in this pull request https://github.com/pytorch/pytorch/pull/12746 but perhaps it’s not yet available in the latest version?

Hi,

I am not sure what you were expecting here?
The first number is just not representable by a float32. So you get the closest possible number.
For the same reason, for the second one, anything after the 6th, 7th digit cannot be represented by a float32 and so you get the closest float32 representable number.

2 Likes