1 /* Decimal 64-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.
5 This file is part of GCC.
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
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
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
22 #if !defined(DECIMAL64)
24 #define DEC64NAME "decimal64" /* Short name */
25 #define DEC64FULLNAME "Decimal 64-bit Number" /* Verbose name */
26 #define DEC64AUTHOR "Mike Cowlishaw" /* Who to blame */
28 #if defined(DECIMAL32)
29 #error decimal64.h must precede decimal32.h for correct DECNUMDIGITS
32 /* parameters for decimal64s */
33 #define DECIMAL64_Bytes 8 /* length */
34 #define DECIMAL64_Pmax 16 /* maximum precision (digits) */
35 #define DECIMAL64_Emax 384 /* maximum adjusted exponent */
36 #define DECIMAL64_Emin -383 /* minimum adjusted exponent */
37 #define DECIMAL64_Bias 398 /* bias for the exponent */
38 #define DECIMAL64_String 24 /* maximum string length, +1 */
39 /* highest biased exponent (Elimit-1) */
40 #define DECIMAL64_Ehigh (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1)
43 #define DECNUMDIGITS DECIMAL64_Pmax /* size if not already defined */
46 #include "decNumber.h" /* context and number library */
49 /* Decimal 64-bit type, accessible by bytes */
52 uint8_t bytes
[DECIMAL64_Bytes
]; /* decimal64: 1, 5, 8, 50 bits */
55 /* special values [top byte excluding sign bit; last two bits are
56 don't-care for Infinity on input, last bit don't-care for NaN] */
57 #if !defined(DECIMAL_NaN)
58 #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
59 #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
60 #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
63 /* Macros for accessing decimal64 fields. These assume the argument
64 is a reference (pointer) to the decimal64 structure */
66 #define decimal64Sign(d) ((unsigned)(d)->bytes[0]>>7)
68 /* Get combination field */
69 #define decimal64Comb(d) (((d)->bytes[0] & 0x7c)>>2)
71 /* Get exponent continuation [does not remove bias] */
72 #define decimal64ExpCon(d) ((((d)->bytes[0] & 0x03)<<6) \
73 | ((unsigned)(d)->bytes[1]>>2))
75 /* Set sign [this assumes sign previously 0] */
76 #define decimal64SetSign(d, b) { \
77 (d)->bytes[0]|=((unsigned)(b)<<7);}
79 /* Set exponent continuation [does not apply bias] */
80 /* This assumes range has been checked and exponent previously 0; type */
81 /* of exponent must be unsigned */
82 #define decimal64SetExpCon(d, e) { \
83 (d)->bytes[0]|=(uint8_t)((e)>>6); \
84 (d)->bytes[1]|=(uint8_t)(((e)&0x3F)<<2);}
86 /* ------------------------------------------------------------------ */
88 /* ------------------------------------------------------------------ */
91 #define decimal64FromString __decimal64FromString
92 #define decimal64ToString __decimal64ToString
93 #define decimal64ToEngString __decimal64ToEngString
94 #define decimal64FromNumber __decimal64FromNumber
95 #define decimal64ToNumber __decimal64ToNumber
98 /* String conversions */
99 decimal64
*decimal64FromString (decimal64
*, char *, decContext
*);
100 char *decimal64ToString (decimal64
*, char *);
101 char *decimal64ToEngString (decimal64
*, char *);
103 /* decNumber conversions */
104 decimal64
*decimal64FromNumber (decimal64
*, decNumber
*, decContext
*);
105 decNumber
*decimal64ToNumber (decimal64
*, decNumber
*);