Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 40d4000
  • /
  • src
  • /
  • math
  • /
  • isqrt.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:e250259500dfe88d5fa25eda7e65ecc8df791fb0
directory badge
swh:1:dir:2685fe8e758ef3e9022e968ae013830f90cd5f51

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
isqrt.cpp
#include <tdc/math/ilog2.hpp>

#include <tdc/math/isqrt.hpp>
#include <tdc/util/likely.hpp>

uint64_t tdc::math::isqrt_floor(const uint64_t x) {
    if(tdc_unlikely(x < 4ULL)) {
        return uint64_t(x > 0);
    }
    
    uint64_t e = ilog2_floor(x) >> 1;
    uint64_t r = 1ULL;

    while(e--) {
        const uint64_t cur = x >> (e << 1ULL);
        const uint64_t sm = r << 1ULL;
        const uint64_t lg = sm + 1ULL;
        r = (sm + (lg * lg <= cur));
    }
    return r;
}

uint64_t tdc::math::isqrt_ceil(const uint64_t x) {
    const uint64_t r = isqrt_floor(x);
    return r + (r * r < x);
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API