Implementation of adapters for 128 bit versions of standard functions.
More...
#include <string>
#include <charconv>
#include <cstdlib>
#include <quadmath.h>
#include <gmp.h>
#include "algo.h"
#include "dbc.h"
#include "helper.h"
#include "adapter128.h"
#include "error.h"
#include "dry.h"
|
| string | __int128_to_string (const __int128 p_z) |
| | We need an adapter function, because __int128 isn't supported by std::to_string().
|
| |
| string | __float128_to_string (__float128 p_float, size_t p_precision) |
| | We need an adapter function, because __float128 isn't supported by std::to_string().
|
| |
| __int128 | string_to___int128 (const string &p_s) |
| | We need an adapter function, because __int128 isn't supported by the standard library.
|
| |
| __float128 | string_to___float128 (const string &p_s) |
| | We need an adapter function, because __float128 isn't supported by the standard library.
|
| |
| bool | mpz_t_to___int128 (__int128 &p_dst, const mpz_t p_src) |
| | Converts a mpz_t into an __int128.
|
| |
| void | __int128_to_mpz_t (mpz_t p_dst, __int128 p_src) |
| | Converts an __int128 into a mpz_t.
|
| |
| void | __float128_to_mpf_t (mpf_t p_dst, __float128 p_f128) |
| | Converts a __float128 to a mpf_t.
|
| |
Implementation of adapters for 128 bit versions of standard functions.
- Copyright
Leonardus, a minimalist stack-based programming system.
Copyright (C) 2025 Andreas Muckenschnabel
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see https://www.gnu.org/licenses/.
◆ __float128_to_mpf_t()
| void __float128_to_mpf_t |
( |
mpf_t |
p_dst, |
|
|
__float128 |
p_f128 |
|
) |
| |
Converts a __float128 to a mpf_t.
Note: GMP doesn't support 128 Bit floats directly.
- Parameters
-
| [out] | p_dst | The destination mpf_t. |
| [in] | p_f128 | The source __float128. |
◆ __float128_to_string()
| string __float128_to_string |
( |
__float128 |
p_float, |
|
|
size_t |
p_precision |
|
) |
| |
We need an adapter function, because __float128 isn't supported by std::to_string().
Implementation with GNU quadmath.
- Parameters
-
| [in] | p_float | The __float128 to convert. |
| [in] | p_precision | The number of decimal digits. |
- Returns
- std::string ... The string-representation of p_float.
◆ __int128_to_mpz_t()
| void __int128_to_mpz_t |
( |
mpz_t |
p_dst, |
|
|
__int128 |
p_src |
|
) |
| |
Converts an __int128 into a mpz_t.
- Parameters
-
| [out] | p_dst | The destination mpz_t. |
| [in] | p_src | The source __int128. |
◆ __int128_to_string()
| string __int128_to_string |
( |
__int128 |
p_z | ) |
|
We need an adapter function, because __int128 isn't supported by std::to_string().
- Parameters
-
| [in] | p_z | We need a representation for this integer. |
- Returns
- std::string ... The string-representation of p_z.
◆ mpz_t_to___int128()
| bool mpz_t_to___int128 |
( |
__int128 & |
p_dst, |
|
|
const mpz_t |
p_src |
|
) |
| |
Converts a mpz_t into an __int128.
- Parameters
-
| [out] | p_dst | The destination __int128. |
| [in] | p_src | The source mpz_t. |
- Returns
- bool ... true, if mpz_t fits into 128 bit integer, false otherwise.
◆ string_to___float128()
| __float128 string_to___float128 |
( |
const std::string & |
p_s | ) |
|
We need an adapter function, because __float128 isn't supported by the standard library.
Implemented with GNU quadmath. We accept loosing unsignificant digits during conversion.
- Parameters
-
| [in] | p_s | Contains a string representation. |
- Returns
- __float128 ... The float.
◆ string_to___int128()
| __int128 string_to___int128 |
( |
const std::string & |
p_s | ) |
|
We need an adapter function, because __int128 isn't supported by the standard library.
- Precondition
- p_s format is: [-][digit]+
-
MIN_INT <= integer interpretation <= MAX_INT
- Parameters
-
| [in] | p_s | The string to convert. |
- Returns
- __int128 ... The integer interpretation.