{"id":21453454,"url":"https://github.com/lapets/isqrt","last_synced_at":"2025-07-14T23:31:42.806Z","repository":{"id":45022507,"uuid":"117399149","full_name":"lapets/isqrt","owner":"lapets","description":"Efficient pure-Python implementation of the integer square root function.","archived":false,"fork":false,"pushed_at":"2023-05-25T21:59:48.000Z","size":62,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-14T16:23:25.603Z","etag":null,"topics":["arithmetic","integers","python","python-library","square-root","square-root-estimate"],"latest_commit_sha":null,"homepage":"http://pypi.org/project/isqrt","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lapets.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-14T03:41:05.000Z","updated_at":"2022-08-19T12:27:31.000Z","dependencies_parsed_at":"2022-09-22T10:58:24.669Z","dependency_job_id":null,"html_url":"https://github.com/lapets/isqrt","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fisqrt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fisqrt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fisqrt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lapets%2Fisqrt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lapets","download_url":"https://codeload.github.com/lapets/isqrt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225351493,"owners_count":17460843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arithmetic","integers","python","python-library","square-root","square-root-estimate"],"created_at":"2024-11-23T04:39:41.784Z","updated_at":"2024-11-23T04:39:42.262Z","avatar_url":"https://github.com/lapets.png","language":"Python","readme":"=====\nisqrt\n=====\n\nEfficient pure-Python implementation of the integer square root function.\n\n|pypi| |actions| |coveralls|\n\n.. |pypi| image:: https://badge.fury.io/py/isqrt.svg\n   :target: https://badge.fury.io/py/isqrt\n   :alt: PyPI version and link.\n\n.. |actions| image:: https://github.com/lapets/isqrt/workflows/lint-test-cover/badge.svg\n   :target: https://github.com/lapets/isqrt/actions/workflows/lint-test-cover.yml\n   :alt: GitHub Actions status.\n\n.. |coveralls| image:: https://coveralls.io/repos/github/lapets/isqrt/badge.svg?branch=main\n   :target: https://coveralls.io/github/lapets/isqrt?branch=main\n   :alt: Coveralls test coverage summary.\n\nPurpose\n-------\nGiven an arbitrarily large non-negative integer ``n``, the `integer square root \u003chttps://en.wikipedia.org/wiki/Integer_square_root\u003e`__ function finds the largest integer ``r`` such that ``r**2 \u003c= n`` and ``(r + 1)**2 \u003e n``.\n\n.. |math_isqrt| replace:: ``math.isqrt``\n.. _math_isqrt: https://docs.python.org/3/library/math.html#math.isqrt\n\n.. |math_sqrt| replace:: ``math.sqrt``\n.. _math_sqrt: https://docs.python.org/3/library/math.html#math.sqrt\n\n**The built-in** |math_isqrt|_ **function was introduced in Python 3.8 and should normally be used instead of the function defined in this library.** To provide the best performance possible while retaining backwards-compatible behavior for this library, the implementation in this library invokes |math_isqrt|_ when it is available. If |math_isqrt|_ is not available, this library attempts to use |math_sqrt|_ and then (if |math_sqrt|_ does not produce the correct result or the input is outside the range supported by |math_sqrt|_) defaults to a pure-Python implementation in which the number of executed Python arithmetic operations is linear in the bit length of the input integer.\n\nInstallation and Usage\n----------------------\nThis library is available as a `package on PyPI \u003chttps://pypi.org/project/isqrt\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install isqrt\n\nThe library can be imported in the usual way:\n\n.. code-block:: python\n\n    from isqrt import isqrt\n\nExamples\n^^^^^^^^\nThe exported function ``isqrt`` provides a pure-Python implementation of the `integer square root \u003chttps://en.wikipedia.org/wiki/Integer_square_root\u003e`__ algorithm:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e isqrt(4)\n    2\n    \u003e\u003e\u003e isqrt(16)\n    4\n    \u003e\u003e\u003e list(map(isqrt, range(16, 26)))\n    [4, 4, 4, 4, 4, 4, 4, 4, 4, 5]\n    \u003e\u003e\u003e isqrt(2**30000) == 2**15000\n    True\n\nDevelopment\n-----------\nAll installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements \u003chttps://peps.python.org/pep-0621\u003e`__ for various development tasks. This makes it possible to specify additional options (such as ``test``, ``lint``, and so on) when performing installation using `pip \u003chttps://pypi.org/project/pip\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install .[test,lint]\n\nTesting and Conventions\n^^^^^^^^^^^^^^^^^^^^^^^\nAll unit tests are executed and their coverage is measured when using `pytest \u003chttps://docs.pytest.org\u003e`__ (see the ``pyproject.toml`` file for configuration details):\n\n.. code-block:: bash\n\n    python -m pip install .[test]\n    python -m pytest\n\nAlternatively, all unit tests are included in the module itself and can be executed using `doctest \u003chttps://docs.python.org/3/library/doctest.html\u003e`__:\n\n.. code-block:: bash\n\n    python src/isqrt/isqrt.py -v\n\nStyle conventions are enforced using `Pylint \u003chttps://pylint.readthedocs.io\u003e`__:\n\n.. code-block:: bash\n\n    python -m pip install .[lint]\n    python -m pylint src/isqrt\n\nAcknowledgments\n^^^^^^^^^^^^^^^\nThe initial version of this function was `posted \u003chttp://stackoverflow.com/a/23279113/2738025\u003e`__ on Stack Overflow. A `more efficient version \u003chttps://gist.github.com/castle-bravo/e841684d6bad8e0598e31862a7afcfc7\u003e`__ was implemented by Alexander Gosselin. The implementation in this package is adapted directly from these previous implementations.\n\nContributions\n^^^^^^^^^^^^^\nIn order to contribute to the source code, open an issue or submit a pull request on the `GitHub page \u003chttps://github.com/lapets/isqrt\u003e`__ for this library.\n\nVersioning\n^^^^^^^^^^\nBeginning with version 0.10.0, the version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 \u003chttps://semver.org/#semantic-versioning-200\u003e`__.\n\nPublishing\n^^^^^^^^^^\nThis library can be published as a `package on PyPI \u003chttps://pypi.org/project/isqrt\u003e`__ by a package maintainer. First, install the dependencies required for packaging and publishing:\n\n.. code-block:: bash\n\n    python -m pip install .[publish]\n\nEnsure that the correct version number appears in the ``pyproject.toml`` file. Create and push a tag for this version (replacing ``?.?.?`` with the version number):\n\n.. code-block:: bash\n\n    git tag ?.?.?\n    git push origin ?.?.?\n\nRemove any old build/distribution files. Then, package the source into a distribution archive:\n\n.. code-block:: bash\n\n    rm -rf build dist src/*.egg-info\n    python -m build --sdist --wheel .\n\nFinally, upload the package distribution archive to `PyPI \u003chttps://pypi.org\u003e`__:\n\n.. code-block:: bash\n\n    python -m twine upload dist/*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flapets%2Fisqrt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flapets%2Fisqrt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flapets%2Fisqrt/lists"}