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