ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Wide.h File Reference

The arithmetic of two words that C++20 does not spell, in one form for every compiler: the product of two words of 64 bits in two, the quotient and the remainder of a number of two words by one, and the signed integers of 128 bits. More...

#include "ADS/Portable.h"
#include <bit>
#include <compare>
#include <concepts>
#include <cstdint>
#include <type_traits>

Go to the source code of this file.

Namespaces

namespace  ADS

Detailed description

The arithmetic of two words that C++20 does not spell, in one form for every compiler: the product of two words of 64 bits in two, the quotient and the remainder of a number of two words by one, and the signed integers of 128 bits.

With ADS_WITH_BOOST the product is that of Boost.Multiprecision (boost::multiprecision::multiply() into a uint128_t), which Boost computes by the instruction of the processor where there is one (one mul on x86-64, the same code as the integers of 128 bits of GCC and Clang); without it, and in a constant expression, it is the arithmetic on the halves of 32 bits (wideProductHalves() of Portable.h, which is also the product of BigInteger.h when ADS_BIGINT_PORTABLE is defined). The division is that of two digits of 32 bits by one, twice, after the divisor is shifted to its top bit (Hacker's Delight, figure 9-3); the signed integer of 128 bits is a pair of words in two's complement. They are details of the implementation, out of the API reference, and their arithmetic is on the theory page of the area.

See also
H. S. Warren, Hacker's Delight, 2nd ed., Addison-Wesley, 2012, section 9-4 (the division of two digits by one)
D. E. Knuth, The Art of Computer Programming, Volume 2: Seminumerical Algorithms, 3rd ed., Addison-Wesley, 1997, section 4.3.1, Algorithms M and D
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa