The number of '16894685.' can not compute by PyTorch.

Tnak: <p>I found a very strange phenomenon. Specifically, I initialized a data AAA = torch.tensor(16894685.). However, when I try to print this value, the number displayed is ‘16894684.’. Then I tried to make it print 1. using AAA + 1 - AAA, but the weird thing happened again. The result of the calculation is 0, which makes my experiments impossible to continue, because the loss will be NAN. When I convert tensor to numpy type data, the calculation result is normal. I’m very confused and looking forward to someone who can help me with my doubts. The pictures show the result of my program running.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/f/b/fb455affa91a316e9f5295537c2bf6ddf4fdc64e.png" alt="微信图片_20220708101837" data-base62-sha1="zQQrbvBPD7MNgoGI6QrCcIg2tqu" width="461" height="110"><br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/3/4/34d9fdc797b9368095cc762f061272091af10a30.png" alt="微信图片_20220708101847" data-base62-sha1="7xxS6LhF3DfH7ylp07LUMX8aGvS" width="477" height="123"><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/3/f376e96cc87a1df2d3a91c3a9f539b4fc4eff59e.png" data-download-href="https://discuss.pytorch.org/uploads/default/f376e96cc87a1df2d3a91c3a9f539b4fc4eff59e" title="微信图片_20220708101855"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/3/f376e96cc87a1df2d3a91c3a9f539b4fc4eff59e_2_690x194.png" alt="微信图片_20220708101855" data-base62-sha1="yJMN9b2UpbR5w42CMvXB6q1vDtA" width="690" height="194" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/3/f376e96cc87a1df2d3a91c3a9f539b4fc4eff59e_2_690x194.png, https://discuss.pytorch.org/uploads/default/original/3X/f/3/f376e96cc87a1df2d3a91c3a9f539b4fc4eff59e.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/f/3/f376e96cc87a1df2d3a91c3a9f539b4fc4eff59e.png 2x" data-dominant-color="F5F6F5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">微信图片_20220708101855</span><span class="informations">826×233 18 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>This is expected as you are using <code>float32</code> as the default <code>dtype</code> in PyTorch, which starts to round to multiple of 2 (even numbers) in the interval of <code>[2**24, 2**25]</code>, which your value is in. Take a look at <a href="https://en.wikipedia.org/wiki/Single-precision_floating-point_format">this Wikipedia page</a> for more information and check the <code>Precision limitations on integer values</code> section.</p>
<aside class="quote no-group" data-username="Tnak" data-post="1" data-topic="156153">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tnak/48/47302_2.png" class="avatar"> Tnak:</div>
<blockquote>
<p>When I convert tensor to numpy type data, the calculation result is normal.</p>
</blockquote>
</aside>
<p><code>numpy</code> uses <code>float64</code> by default and transforming your PyTorch tensor to <code>float64</code> too would work:</p>
<pre data-code-wrap="python"><code class="lang-python">AAA = torch.tensor(16894685., dtype=torch.float64)
AAA + 1 - AAA
</code></pre>

Tnak: <p>Thank you very much. I looked at the float type as you suggested and it does exactly what you said. When I use float 64, the above problem is solved fine. Thank you again!<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/6/f/6ff1b3afe0a3d6c6341d96397e2800a49ea7b5cd.png" alt="微信图片_20220708124737" data-base62-sha1="fYiQh62THu5mauZkrOcJYeYl3g9" width="562" height="244"></p>