A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20180322/571bb01e/attachment.html below:

<div dir="auto">Ok. I'm wrong on that example.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 21, 2018, 9:11 PM Tim Peters <<a href="mailto:tim.peters@gmail.com">tim.peters@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[David Mertz <<a href="mailto:mertz@gnosis.cx" target="_blank" rel="noreferrer">mertz@gnosis.cx</a>>]<br>
>> For example, this can be true (even without reaching inf):<br>
>><br>
>> >>> x.is_integer()<br>
>> True<br>
>> >>> (math.sqrt(x**2)).is_integer()<br>
>> False<br>
<br>
[Mark Dickinson <<a href="mailto:dickinsm@gmail.com" target="_blank" rel="noreferrer">dickinsm@gmail.com</a>> ]<br>
> If you have a moment to share it, I'd be interested to know what value of<br>
> `x` you used to achieve this, and what system you were on. This can't happen<br>
> under IEEE 754 arithmetic.<br>
<br>
I expect it might happen under one of the directed rounding modes<br>
(like "to +infinity").<br>
<br>
But under 754 binary round-nearest/even arithmetic, it's been formally<br>
proved that sqrt(x*x) == x exactly for all non-negative finite x such<br>
that x*x neither overflows nor underflows (and .as_integer() has<br>
nothing to do with that very strong result):<br>
<br>
  Â  <a href="https://hal.inria.fr/hal-01148409/document" rel="noreferrer noreferrer" target="_blank">https://hal.inria.fr/hal-01148409/document</a><br>
<br>
OTOH, the paper notes that it's not necessarily true for IEEE decimal<br>
arithmetic; e.g.,<br>
<br>
>>> import decimal<br>
>>> decimal.getcontext().prec = 4<br>
>>> (decimal.Decimal("31.66") ** 2).sqrt()  # result is 1 ulp smaller<br>
Decimal('31.65')<br>
<br>
>>> decimal.getcontext().prec = 5<br>
>>> (decimal.Decimal("31.660") ** 2).sqrt() # result is 1 ulp larger<br>
Decimal('31.661')<br>
</blockquote></div>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4