This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add non integral tests for `sqrt()`
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.11, Python 3.10
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AjithRamachandran, mark.dickinson, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-06-09 15:14 by AjithRamachandran, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26625 merged AjithRamachandran, 2021-06-09 15:31
Messages (4)
msg395549 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-06-10 16:27
New changeset 90cd4330329a99e52f7141db5e0a469d30088e66 by Ajith Ramachandran in branch 'main':
bpo-44364:Add non integral tests for `sqrt()` (#26625)
https://github.com/python/cpython/commit/90cd4330329a99e52f7141db5e0a469d30088e66
msg395563 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-06-10 19:18
>>> math.sqrt(2.5) == 2.5**0.5
True
>>> math.sqrt(25.25) == 25.25**0.5
True

If we test the precision of math.sqrt(), would not be better to test it with data for which naive way of calculating the root returns different result? For example 2921 is the smallest integers for which math.sqrt(x) > x**0.5, and 3541 is the smallest integers for which math.sqrt(x) < x**0.5.
msg395564 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-06-10 19:33
65733 and 262694 are integers in range 1..1000000 with largest relative errors of naive square root (with different signs).

33031 and 524557 are integers in range 1..1000000 with largest relative errors of naive cube root (with different signs).
msg395566 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2021-06-10 19:41
> 2921 is the smallest integers for which math.sqrt(x) > x**0.5

This is platform-dependent. On my machine, for example, `math.sqrt(2921) == 2921**0.5` returns `True`.

I don't see a lot of value in additional tests here; we're only wrapping the libm sqrt, so we only really need enough testing to catch possible implementation errors in that wrapping. But testing only integers with an exact square root doesn't seem enough.
History
Date User Action Args
2022-04-11 14:59:46adminsetgithub: 88530
2021-06-10 19:41:09mark.dickinsonsetmessages: + msg395566
2021-06-10 19:33:06serhiy.storchakasetmessages: + msg395564
2021-06-10 19:18:08serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg395563
2021-06-10 16:29:32mark.dickinsonsetstatus: open -> closed
stage: patch review -> resolved
2021-06-10 16:27:34mark.dickinsonsetmessages: + msg395549
2021-06-09 15:51:52mark.dickinsonsetnosy: + mark.dickinson
2021-06-09 15:31:44AjithRamachandransetkeywords: + patch
stage: patch review
pull_requests: + pull_request25210
2021-06-09 15:14:51AjithRamachandrancreate