fixed_point128 1.0.1.0
128 bit integer, fixed point and floating point arithmetic for C++20
Loading...
Searching...
No Matches
int128_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 int128_t.h
32 * @brief 128-bit signed integer type.
33 *
34 * Provides @ref fp128::int128_t, a software-emulated 128-bit signed integer using
35 * two's complement representation. Supports full arithmetic, bitwise, comparison,
36 * and conversion operators, as well as math functions (abs, sqrt, log, log2,
37 * log10, pow).
38 * All methods are inline for maximum performance.
39 *
40 * @see int128_shared.h for the class template both 128 bit integer types alias.
41 * @see fp128_shared.h for supporting intrinsics and utilities.
42 */
43
44#ifndef FP128_INT128_T_H
45#define FP128_INT128_T_H
46
47#include "int128_shared.h"
48
49namespace fp128
50{
51
52/***********************************************************************************
53 * Main Code
54 ************************************************************************************/
55
56/**
57 * @typedef int128_t
58 * @brief 128 bit signed integer type.
59 *
60 * An alias of the signed instantiation of @ref fp128::int128_base, which holds the entire
61 * implementation. This type implements the standard operators a signed integer type has.<BR>
62 * All of int128_t's methods are inline for maximum performance.
63 *
64 * <B>Implementation notes:</B>
65 * <UL>
66 * <LI>Values are stored in two's complement, so the bit patterns of the shared operations match
67 * the unsigned type exactly.</LI>
68 * <LI>Overflow is handled silently, similar to builtin integer operations.</LI>
69 * <LI>An int128_t object is not thread safe. Accessing a const object from multiple threads is safe.</LI>
70 * <LI>int128_t is <B>conditionally safe</B>, 2 different non const objects can be accessed concurrently.</LI>
71 * <LI>Only 64 bit builds are supported.</LI>
72 * <LI>Being an alias rather than a distinct class, int128_t cannot be forward declared. Include
73 * this header instead.</LI>
74 * </UL>
75 */
77
78/**
79 * @brief User-defined literal for constructing int128_t from a string.
80 *
81 * Defined at namespace scope rather than as a friend of the class template: its signature does
82 * not depend on the template parameter, so a friend definition inside the template would be
83 * emitted once per instantiation and collide. Literal operators are found by ordinary unqualified
84 * lookup only, never by ADL, so namespace scope is where they belong anyway.
85 *
86 * @param literal Decimal or hexadecimal digits with an optional sign, see the
87 * int128_t(const char*) constructor.
88 * @return The parsed value.
89 */
90[[nodiscard]] FP128_INLINE int128_t operator""_int128(const char* literal)
91{
92 return int128_t(literal);
93}
94
95} // namespace fp128
96
97#endif // FP128_INT128_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< true > int128_t
128 bit signed integer type.
Definition int128_t.h:76