|
NTLib - Number Theory Library 0.9
|
Primary module interface unit for module base. More...
#include <algorithm>#include <array>#include <bit>#include <cassert>#include <climits>#include <cmath>#include <cstdint>#include <functional>#include <ranges>#include <type_traits>import base:concepts;
Functions | |
| template<Integer T> | |
| constexpr bool | ntlib::is_odd (T n) noexcept |
| Checks whether a given number is odd. | |
| template<Integer T> | |
| constexpr bool | ntlib::is_even (T n) noexcept |
| Checks whether a given number is even. | |
| template<AdditiveGroup T> | |
| constexpr T | ntlib::abs (T n) noexcept |
| Computes the absolute value of a given number. | |
| template<AdditiveGroup T> | |
| constexpr T | ntlib::difference (T a, T b) noexcept |
| Computes the difference between two numbers. | |
| template<std::totally_ordered T> | |
| constexpr int | ntlib::sgn (T n) noexcept |
| Computes the sign of a given number. | |
| template<Integer T> | |
| constexpr std::pair< T, T > | ntlib::odd_part (T n) noexcept |
| Given a number n, computes a pair (e, o), such that n=2^e*o. | |
| template<Integer T> | |
| constexpr T | ntlib::gcd (T a, T b) noexcept |
| Computes the greatest common divisor of two numbers using the Euclidean algorithm. | |
| template<Integer T> | |
| constexpr T | ntlib::gcd (std::initializer_list< T > list) noexcept |
| Computes the greatest common divisor of a list of numbers. | |
| template<Integer T> | |
| constexpr T | ntlib::lcm (T a, T b) noexcept |
| Computes the least common multiple of two numbers. | |
| template<Integer T> | |
| constexpr T | ntlib::lcm (std::initializer_list< T > list) noexcept |
| Computes the least common multiple of a list of numbers. | |
| template<Integer T> | |
| constexpr std::tuple< T, T, T > | ntlib::extended_euclid (T a, T b) noexcept |
| Extended Euclidean algorithm. | |
| template<MultiplicativeMonoid A, Integer B> | |
| constexpr A | ntlib::pow (A a, B b) noexcept |
| Binary exponentation. | |
| template<Integer T> | |
| constexpr T | ntlib::ilog2 (T n) noexcept |
| Computes the integer part of the binary logarithm of a given number. | |
| template<Integer T> | |
| constexpr T | ntlib::isqrt (T n) noexcept |
| Computes the integer square root of a given number. | |
| template<Integer T> | |
| constexpr bool | ntlib::is_square (T n) noexcept |
| Tests, if a given number is a perfect square. | |
| template<Integer T> | |
| constexpr T | ntlib::factorial (T n) noexcept |
| Computes the factorial of a given number. | |
Variables | |
| template<Integer T> | |
| constexpr auto | ntlib::SMALL_PRIMES |
| A list with all prime numbers up to ntlib::SMALL_PRIMES_BIGGEST. | |
| template<Integer T> | |
| constexpr T | ntlib::SMALL_PRIMES_BIGGEST |
| Helper constant to get the biggest among the small primes in ntlib::SMALL_PRIMES. | |
Primary module interface unit for module base.
|
nodiscardconstexprexportnoexcept |
Computes the absolute value of a given number.
| T | An additive group. |
| n | The given number. |
|
nodiscardconstexprexportnoexcept |
Computes the difference between two numbers.
| T | An additive group. |
| a | The first number. |
| b | The second number. |
|
nodiscardconstexprexportnoexcept |
Extended Euclidean algorithm.
Given two integers \(a\) and \(b\), finds whole number solutions for \(a \cdot x + b \cdot y = \text{gcd}(a,b)\).
| T | An integer-like type. |
| a | The first number. |
| b | The second number. |
|
nodiscardconstexprexportnoexcept |
Computes the factorial of a given number.
| T | An integer-like type. |
| n | The given number. |
|
nodiscardconstexprexportnoexcept |
Computes the greatest common divisor of a list of numbers.
| T | An integer-like type. |
| list | The list of numbers. Must not be empty. |
|
nodiscardconstexprexportnoexcept |
Computes the greatest common divisor of two numbers using the Euclidean algorithm.
The greatest common divisor of two numbers a and b (not both zero) is the smallest positive number that divides both a and b.
Complexity: \(O(\log a + \log b)\)
| T | An integer-like type. |
| a | The first number. |
| b | The second number. |
|
nodiscardconstexprexportnoexcept |
Computes the integer part of the binary logarithm of a given number.
| T | An integer-like type. |
| n | The given number. |
|
nodiscardconstexprexportnoexcept |
Checks whether a given number is even.
| T | An integer-like type. |
| n | The given number. |
|
nodiscardconstexprexportnoexcept |
Checks whether a given number is odd.
| T | An integer-like type. |
| n | The given number. |
|
nodiscardconstexprexportnoexcept |
Tests, if a given number is a perfect square.
Uses ideas from this site: https://math.stackexchange.com/questions/131330/detecting-perfect-squares-faster-than-by-extracting-square-root/712818#712818
Complexity: \(O(\log n)\)
| T | An integer-like type. |
| n | The given number. |
|
nodiscardconstexprexportnoexcept |
Computes the integer square root of a given number.
| T | An integer-like type. |
| n | The given number. Must be non-negative. |
|
nodiscardconstexprexportnoexcept |
Computes the least common multiple of a list of numbers.
| T | An integer-like type. |
| list | The list of numbers. Must not be empty. |
|
nodiscardconstexprexportnoexcept |
Computes the least common multiple of two numbers.
The least common multiple of two non-zero integers a and b is the smallest positive integer that can be divided by both a and b.
Complexity: \(O(\log a + \log b)\)
| T | An integer-like type. |
| a | The first number. |
| b | The second number. |
|
nodiscardconstexprexportnoexcept |
Given a number n, computes a pair (e, o), such that n=2^e*o.
| T | An integer-like type. |
| n | The number n to decompose. |
|
nodiscardconstexprexportnoexcept |
Binary exponentation.
Complexity: \(O(\log b)\)
| A | A multiplicative monoid. |
| B | An integer-like type. |
| a | The base. |
| b | The exponent, non-negative. |
|
nodiscardconstexprexportnoexcept |
Computes the sign of a given number.
| T | An integer-like type. |
| n | The given number. |
|
constexprexport |
A list with all prime numbers up to ntlib::SMALL_PRIMES_BIGGEST.
Can be used for trial division in primality tests and prime factorizations.
| T | An integer-like type. |
|
constexprexport |
Helper constant to get the biggest among the small primes in ntlib::SMALL_PRIMES.
| T | An integer-like type. |