ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BinaryInteger.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File BinaryInteger.h --------------------------*/
3/*--------------------------------------------------------------------------*/
41/*--------------------------------------------------------------------------*/
42/*----------------------------- DEFINITIONS --------------------------------*/
43/*--------------------------------------------------------------------------*/
44
45#ifndef __ADS_BinaryInteger
46 #define __ADS_BinaryInteger
47/* self-identification: #endif constant */
48
49/*--------------------------------------------------------------------------*/
50/*------------------------------ INCLUDES ----------------------------------*/
51/*--------------------------------------------------------------------------*/
52
53#include "ADS/Contract.h"
55
56#include <algorithm>
57#include <cstddef>
58#include <cstdint>
59#include <vector>
60
61/*--------------------------------------------------------------------------*/
62/*--------------------------- NAMESPACE ------------------------------------*/
63/*--------------------------------------------------------------------------*/
64
65namespace ADS
66{
67
68using Bits = std::vector< int >;
69
84inline Bits toBits( std::uint64_t x , std::size_t n = 0 );
85
99inline std::uint64_t fromBits( const Bits & b );
100
118inline Bits carry( const std::vector< long > & c );
119
136inline Bits binaryAdd( const Bits & X , const Bits & Y );
137
140inline std::vector< long > widen( const Bits & X );
141
156inline Bits multiplyBinarySchool( const Bits & X , const Bits & Y ,
157 long * mults = nullptr );
158
172inline Bits multiplyBinaryFour( const Bits & X , const Bits & Y ,
173 long * mults = nullptr );
174
188inline Bits multiplyBinaryKaratsuba( const Bits & X , const Bits & Y ,
189 long * mults = nullptr );
190
207inline std::uint64_t ahmes( std::uint64_t a , std::uint64_t b ,
208 long * steps = nullptr );
209
210/*--------------------------------------------------------------------------*/
211
212} // end( namespace ADS )
213
214/*--------------------------------------------------------------------------*/
215/*-------------------------- IMPLEMENTATION --------------------------------*/
216/*--------------------------------------------------------------------------*/
217
218#include "ADS/numeric/impl/BinaryInteger.tpp"
219
220/*--------------------------------------------------------------------------*/
221
222#endif /* BinaryInteger.h included */
223
224/*--------------------------------------------------------------------------*/
225/*------------------------ End File BinaryInteger.h ------------------------*/
226/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The product of two polynomials of coefficients each, the vectors and from the constant one,...
Bits multiplyBinarySchool(const Bits &X, const Bits &Y, long *mults=nullptr)
the product by the method of the school, ; the products of two bits added to *mults,...
Bits carry(const std::vector< long > &c)
the coefficients , possibly larger than 1 or negative, made bits of the same value by the carries
std::vector< long > widen(const Bits &X)
the bits of as the coefficients of a polynomial in
Bits binaryAdd(const Bits &X, const Bits &Y)
the sum ,
std::uint64_t fromBits(const Bits &b)
the value of the bits, which must be at most 64
Bits multiplyBinaryFour(const Bits &X, const Bits &Y, long *mults=nullptr)
the product by four products of half size, ; the products of two bits added to *mults,...
Bits multiplyBinaryKaratsuba(const Bits &X, const Bits &Y, long *mults=nullptr)
the product by the three products of Karatsuba, ; the products of two bits added to *mults,...
Bits toBits(std::uint64_t x, std::size_t n=0)
the bits of , at least of them
std::uint64_t ahmes(std::uint64_t a, std::uint64_t b, long *steps=nullptr)
the product by the multiplication of Ahmes; the halvings added to *steps, if given
Definition ADT.h:96
std::vector< int > Bits
the bits, the least significant first
Definition BinaryInteger.h:68