decimal128.h revision 1.12 1 1.1 mrg /* Decimal 128-bit format module header for the decNumber C Library.
2 1.12 mrg Copyright (C) 2005-2022 Free Software Foundation, Inc.
3 1.1 mrg Contributed by IBM Corporation. Author Mike Cowlishaw.
4 1.1 mrg
5 1.1 mrg This file is part of GCC.
6 1.1 mrg
7 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
8 1.1 mrg the terms of the GNU General Public License as published by the Free
9 1.1 mrg Software Foundation; either version 3, or (at your option) any later
10 1.1 mrg version.
11 1.1 mrg
12 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 1.1 mrg for more details.
16 1.1 mrg
17 1.1 mrg Under Section 7 of GPL version 3, you are granted additional
18 1.1 mrg permissions described in the GCC Runtime Library Exception, version
19 1.1 mrg 3.1, as published by the Free Software Foundation.
20 1.1 mrg
21 1.1 mrg You should have received a copy of the GNU General Public License and
22 1.1 mrg a copy of the GCC Runtime Library Exception along with this program;
23 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 1.1 mrg <http://www.gnu.org/licenses/>. */
25 1.1 mrg
26 1.1 mrg /* ------------------------------------------------------------------ */
27 1.1 mrg /* Decimal 128-bit format module header */
28 1.1 mrg /* ------------------------------------------------------------------ */
29 1.1 mrg
30 1.1 mrg #if !defined(DECIMAL128)
31 1.1 mrg #define DECIMAL128
32 1.1 mrg #define DEC128NAME "decimal128" /* Short name */
33 1.1 mrg #define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */
34 1.1 mrg #define DEC128AUTHOR "Mike Cowlishaw" /* Who to blame */
35 1.1 mrg
36 1.1 mrg /* parameters for decimal128s */
37 1.1 mrg #define DECIMAL128_Bytes 16 /* length */
38 1.1 mrg #define DECIMAL128_Pmax 34 /* maximum precision (digits) */
39 1.1 mrg #define DECIMAL128_Emax 6144 /* maximum adjusted exponent */
40 1.1 mrg #define DECIMAL128_Emin -6143 /* minimum adjusted exponent */
41 1.1 mrg #define DECIMAL128_Bias 6176 /* bias for the exponent */
42 1.1 mrg #define DECIMAL128_String 43 /* maximum string length, +1 */
43 1.1 mrg #define DECIMAL128_EconL 12 /* exp. continuation length */
44 1.1 mrg /* highest biased exponent (Elimit-1) */
45 1.1 mrg #define DECIMAL128_Ehigh (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1)
46 1.1 mrg
47 1.1 mrg /* check enough digits, if pre-defined */
48 1.1 mrg #if defined(DECNUMDIGITS)
49 1.1 mrg #if (DECNUMDIGITS<DECIMAL128_Pmax)
50 1.1 mrg #error decimal128.h needs pre-defined DECNUMDIGITS>=34 for safe use
51 1.1 mrg #endif
52 1.1 mrg #endif
53 1.1 mrg
54 1.1 mrg #ifndef DECNUMDIGITS
55 1.1 mrg #define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined*/
56 1.1 mrg #endif
57 1.1 mrg #ifndef DECNUMBER
58 1.1 mrg #include "decNumber.h" /* context and number library */
59 1.1 mrg #endif
60 1.1 mrg
61 1.1 mrg /* Decimal 128-bit type, accessible by bytes */
62 1.1 mrg typedef struct {
63 1.1 mrg uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/
64 1.1 mrg } decimal128;
65 1.1 mrg
66 1.1 mrg /* special values [top byte excluding sign bit; last two bits are */
67 1.1 mrg /* don't-care for Infinity on input, last bit don't-care for NaN] */
68 1.1 mrg #if !defined(DECIMAL_NaN)
69 1.1 mrg #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
70 1.1 mrg #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
71 1.1 mrg #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
72 1.1 mrg #endif
73 1.1 mrg
74 1.1 mrg #include "decimal128Local.h"
75 1.1 mrg
76 1.1 mrg /* ---------------------------------------------------------------- */
77 1.1 mrg /* Routines */
78 1.1 mrg /* ---------------------------------------------------------------- */
79 1.1 mrg
80 1.1 mrg #include "decimal128Symbols.h"
81 1.1 mrg
82 1.1 mrg #ifdef __cplusplus
83 1.1 mrg extern "C" {
84 1.1 mrg #endif
85 1.1 mrg
86 1.1 mrg /* String conversions */
87 1.1 mrg decimal128 * decimal128FromString(decimal128 *, const char *, decContext *);
88 1.1 mrg char * decimal128ToString(const decimal128 *, char *);
89 1.1 mrg char * decimal128ToEngString(const decimal128 *, char *);
90 1.1 mrg
91 1.1 mrg /* decNumber conversions */
92 1.1 mrg decimal128 * decimal128FromNumber(decimal128 *, const decNumber *,
93 1.1 mrg decContext *);
94 1.1 mrg decNumber * decimal128ToNumber(const decimal128 *, decNumber *);
95 1.1 mrg
96 1.1 mrg /* Format-dependent utilities */
97 1.1 mrg uint32_t decimal128IsCanonical(const decimal128 *);
98 1.1 mrg decimal128 * decimal128Canonical(decimal128 *, const decimal128 *);
99 1.1 mrg
100 1.1 mrg #ifdef __cplusplus
101 1.1 mrg }
102 1.1 mrg #endif
103 1.1 mrg
104 1.1 mrg #endif
105