]>
Commit | Line | Data |
---|---|---|
473a74b9 BE |
1 | /* Decimal 32-bit format module header for the decNumber C Library |
2 | Copyright (C) 2005 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 2, or (at your option) any later | |
10 | version. | |
11 | ||
9d1d1cd4 BE |
12 | In addition to the permissions in the GNU General Public License, |
13 | the Free Software Foundation gives you unlimited permission to link | |
14 | the compiled version of this file into combinations with other | |
15 | programs, and to distribute those combinations without any | |
16 | restriction coming from the use of this file. (The General Public | |
17 | License restrictions do apply in other respects; for example, they | |
18 | cover modification of the file, and distribution when not linked | |
19 | into a combine executable.) | |
20 | ||
473a74b9 BE |
21 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
22 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
24 | for more details. | |
25 | ||
26 | You should have received a copy of the GNU General Public License | |
27 | along with GCC; see the file COPYING. If not, write to the Free | |
c0173136 BE |
28 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
29 | 02110-1301, USA. */ | |
473a74b9 BE |
30 | |
31 | #if !defined(DECIMAL32) | |
32 | #define DECIMAL32 | |
33 | #define DEC32NAME "decimal32" /* Short name */ | |
34 | #define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */ | |
35 | #define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */ | |
36 | ||
37 | /* parameters for decimal32s */ | |
38 | #define DECIMAL32_Bytes 4 /* length */ | |
39 | #define DECIMAL32_Pmax 7 /* maximum precision (digits) */ | |
40 | #define DECIMAL32_Emax 96 /* maximum adjusted exponent */ | |
41 | #define DECIMAL32_Emin -95 /* minimum adjusted exponent */ | |
42 | #define DECIMAL32_Bias 101 /* bias for the exponent */ | |
43 | #define DECIMAL32_String 15 /* maximum string length, +1 */ | |
44 | /* highest biased exponent (Elimit-1) */ | |
45 | #define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1) | |
46 | ||
47 | #ifndef DECNUMDIGITS | |
48 | #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined */ | |
49 | #endif | |
50 | #ifndef DECNUMBER | |
51 | #include "decNumber.h" /* context and number library */ | |
52 | #endif | |
53 | ||
54 | /* Decimal 32-bit type, accessible by bytes */ | |
55 | typedef struct | |
56 | { | |
57 | uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits */ | |
58 | } decimal32; | |
59 | ||
60 | /* special values [top byte excluding sign bit; last two bits are | |
61 | don't-care for Infinity on input, last bit don't-care for NaN] */ | |
62 | #if !defined(DECIMAL_NaN) | |
63 | #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ | |
64 | #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ | |
65 | #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ | |
66 | #endif | |
67 | ||
68 | /* Macros for accessing decimal32 fields. These assume the argument | |
69 | is a reference (pointer) to the decimal32 structure */ | |
70 | /* Get sign */ | |
71 | #define decimal32Sign(d) ((unsigned)(d)->bytes[0]>>7) | |
72 | ||
73 | /* Get combination field */ | |
74 | #define decimal32Comb(d) (((d)->bytes[0] & 0x7c)>>2) | |
75 | ||
76 | /* Get exponent continuation [does not remove bias] */ | |
77 | #define decimal32ExpCon(d) ((((d)->bytes[0] & 0x03)<<4) \ | |
78 | | ((unsigned)(d)->bytes[1]>>4)) | |
79 | ||
80 | /* Set sign [this assumes sign previously 0] */ | |
81 | #define decimal32SetSign(d, b) { \ | |
82 | (d)->bytes[0]|=((unsigned)(b)<<7);} | |
83 | ||
79b87c74 MM |
84 | /* Clear sign */ |
85 | #define decimal32ClearSign(d) {(d)->bytes[0]&=~0x80;} | |
86 | ||
87 | /* Flip sign */ | |
88 | #define decimal32FlipSign(d) {(d)->bytes[0]^=0x80;} | |
89 | ||
473a74b9 BE |
90 | /* Set exponent continuation [does not apply bias] */ |
91 | /* This assumes range has been checked and exponent previously 0; */ | |
92 | /* type of exponent must be unsigned */ | |
93 | #define decimal32SetExpCon(d, e) { \ | |
94 | (d)->bytes[0]|=(uint8_t)((e)>>4); \ | |
95 | (d)->bytes[1]|=(uint8_t)(((e)&0x0F)<<4);} | |
96 | ||
97 | /* ------------------------------------------------------------------ */ | |
98 | /* Routines */ | |
99 | /* ------------------------------------------------------------------ */ | |
100 | ||
101 | #ifdef IN_LIBGCC2 | |
79b87c74 | 102 | #ifndef decimal32FromString |
473a74b9 BE |
103 | #define decimal32FromString __decimal32FromString |
104 | #define decimal32ToString __decimal32ToString | |
105 | #define decimal32ToEngString __decimal32ToEngString | |
106 | #define decimal32FromNumber __decimal32FromNumber | |
107 | #define decimal32ToNumber __decimal32ToNumber | |
108 | #endif | |
79b87c74 | 109 | #endif |
473a74b9 BE |
110 | |
111 | /* String conversions. */ | |
c5d43417 | 112 | decimal32 *decimal32FromString (decimal32 *, const char *, decContext *); |
aa4f41c1 KG |
113 | char *decimal32ToString (const decimal32 *, char *); |
114 | char *decimal32ToEngString (const decimal32 *, char *); | |
473a74b9 BE |
115 | |
116 | /* decNumber conversions. */ | |
aa4f41c1 KG |
117 | decimal32 *decimal32FromNumber (decimal32 *, const decNumber *, decContext *); |
118 | decNumber *decimal32ToNumber (const decimal32 *, decNumber *); | |
473a74b9 BE |
119 | |
120 | #endif |