How to solve the truncation error problem in pytorch

30 views Asked by At
a = torch.tensor(10.0,dtype=torch.float32)
b = a/299999
c = 0
for i in range(299999):
    c = c+b
print(c)
# tensor(10.0119)

Is the reason for this phenomenon is the truncation error of pytorch floating point numbers? What should I do if the results are consistent before and after. Although this problem can be solved by converting to float64 before, it runs too slowly.

0

There are 0 answers