fixed_point128 1.0.1.0
128 bit integer, fixed point and floating point arithmetic for C++20
Loading...
Searching...
No Matches
uint128_t.h
Go to the documentation of this file.
1/***********************************************************************************
2 MIT License
3
4 Copyright (c) 2025 Eric Gur (ericgur@iname.com)
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23************************************************************************************/
24
25/***********************************************************************************
26 Acknologements
27
28************************************************************************************/
29
30/**
31 * @file uint128_t.h
32 * @brief 128-bit unsigned integer type.
33 *
34 * Provides @ref fp128::uint128_t, a software-emulated 128-bit unsigned integer
35 * with full arithmetic, bitwise, comparison, and conversion operators, as well as
36 * math functions (sqrt, log, log2, log10, pow).
37 * All methods are inline for maximum performance.
38 *
39 * @see int128_shared.h for the class template both 128 bit integer types alias.
40 * @see fp128_shared.h for supporting intrinsics and utilities.
41 */
42
43#ifndef FP128_UINT128_T_H
44#define FP128_UINT128_T_H
45
46#include "int128_shared.h"
47
48namespace fp128
49{
50
51/***********************************************************************************
52 * Main Code
53 ************************************************************************************/
54
55/**
56 * @typedef uint128_t
57 * @brief 128 bit unsigned integer type.
58 *
59 * An alias of the unsigned instantiation of @ref fp128::int128_base, which holds the entire
60 * implementation. This type implements the standard operators an unsigned integer type has.<BR>
61 * All of uint128_t's methods are inline for maximum performance.
62 *
63 * <B>Implementation notes:</B>
64 * <UL>
65 * <LI>Overflow is handled silently, similar to builtin integer operations.</LI>
66 * <LI>A uint128_t object is not thread safe. Accessing a const object from multiple threads is safe.</LI>
67 * <LI>uint128_t is <B>conditionally safe</B>, 2 different non const objects can be accessed concurrently.</LI>
68 * <LI>Only 64 bit builds are supported.</LI>
69 * <LI>Being an alias rather than a distinct class, uint128_t cannot be forward declared. Include
70 * this header instead.</LI>
71 * </UL>
72 */
74
75/**
76 * @brief User-defined literal for constructing uint128_t from a string.
77 *
78 * Defined at namespace scope rather than as a friend of the class template: its signature does
79 * not depend on the template parameter, so a friend definition inside the template would be
80 * emitted once per instantiation and collide. Literal operators are found by ordinary unqualified
81 * lookup only, never by ADL, so namespace scope is where they belong anyway.
82 *
83 * @param literal Decimal or hexadecimal digits, see the uint128_t(const char*) constructor.
84 * @return The parsed value.
85 */
86[[nodiscard]] FP128_INLINE uint128_t operator""_uint128(const char* literal)
87{
88 return uint128_t(literal);
89}
90
91} // namespace fp128
92
93#endif // FP128_UINT128_T_H
128 bit integer class, signed or unsigned depending on the template parameter.
#define FP128_INLINE
Implementation shared by the 128 bit signed and unsigned integer types.
Everything the library provides.
int128_base< false > uint128_t
128 bit unsigned integer type.
Definition uint128_t.h:73