Lattice Tester Online Documentation 0.1.0-861
Software Package For Testing The Uniformity Of Integral Lattices In The Real Space
Loading...
Searching...
No Matches
Util.cc File Reference
#include "latticetester/Util.h"
#include <cstdlib>
#include <cmath>
#include <climits>
#include "NTL/ZZ.h"

Namespaces

namespace  LatticeTester
 Lattice namespace.
 

Macros

#define GERME   9876543219876543L
 
#define NORM53   1.11022302462515654e-16
 
#define NORM52   2.22044604925031308e-16
 

Functions

std::int64_t LatticeTester::RandInt (std::int64_t i, std::int64_t j)
 
Division and modular arithmetic
Remarks
Richard: Pour certaines fonctions, les résultats sont mis dans les premiers arguments de la fonction pour être compatible avec NTL; pour d’autres, ils sont mis dans les derniers arguments pour être compatible avec notre ancienne version de LatMRG en Modula-2. Plutôt détestable. Je crois qu’il faudra un jour réarranger les arguments des fonctions pour qu’elles suivent toutes la même convention que NTL.

This module offers function to perform division and find remainders in a standard way. These functions are usefull in the case where one wants to do divisions or find remainders of operations with negative operands. The reason is that NTL and primitive types do not use the same logic when doing calculations on negative numbers.

Basically, NTL will always floor a division and C++ will always truncate a division (which effectively means the floor function is replaced by a roof function if the answer is a negative number). When calculating the remainder of x/y, both apply the same logic but get a different result because they do not do the same division. In both representations, we have that

\[ y\cdot(x/y) + x%y = x. \]

It turns out that, with negative values, NTL will return an integer with the same sign as y where C++ will return an integer of opposite sign (but both will return the same number modulo y).

std::int64_t LatticeTester::gcd (std::int64_t a, std::int64_t b)
 Returns the value of the greatest common divisor of \(a\) and \(b\) by using Stein's binary GCD algorithm.
 
Mathematical functions

These are complete reimplementation of certain mathematical functions, or wrappers for standard C/C++ functions.

std::int64_t LatticeTester::Factorial (int64_t t)
 Calculates \(t!\), the factorial of \(t\) and returns it as an std::int64_t.
 
Random numbers

All the functions of this module use LFSR258 as an underlying source for pseudo-random numbers.

A free (as in freedom) implementation of this generator can be found at http://simul.iro.umontreal.ca/ as well as the article presenting it. All the functions generating some sort of random number will advance an integer version of LFSR258 by one state and output a transformation of the state to give a double, an int64_t or bits.

double LatticeTester::RandU01 ()
 Returns a random number in \([0, 1)\).
 
std::uint64_t LatticeTester::RandBits (int64_t s)
 Returns the first s pseudo-random bits of the underlying RNG in the form of a s-bit integer.
 
void LatticeTester::SetSeed (std::uint64_t seed)
 Sets the seed of the generator.
 

Macro Definition Documentation

◆ GERME

#define GERME   9876543219876543L

◆ NORM52

#define NORM52   2.22044604925031308e-16

◆ NORM53

#define NORM53   1.11022302462515654e-16