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.
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(DECIMAL32)
24 #define DEC32NAME "decimal32" /* Short name */
25 #define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */
26 #define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */
28 /* parameters for decimal32s */
29 #define DECIMAL32_Bytes 4 /* length */
30 #define DECIMAL32_Pmax 7 /* maximum precision (digits) */
31 #define DECIMAL32_Emax 96 /* maximum adjusted exponent */
32 #define DECIMAL32_Emin -95 /* minimum adjusted exponent */
33 #define DECIMAL32_Bias 101 /* bias for the exponent */
34 #define DECIMAL32_String 15 /* maximum string length, +1 */
35 /* highest biased exponent (Elimit-1) */
36 #define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1)
39 #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined */
42 #include "decNumber.h" /* context and number library */
45 /* Decimal 32-bit type, accessible by bytes */
48 uint8_t bytes
[DECIMAL32_Bytes
]; /* decimal32: 1, 5, 6, 20 bits */
51 /* special values [top byte excluding sign bit; last two bits are
52 don't-care for Infinity on input, last bit don't-care for NaN] */
53 #if !defined(DECIMAL_NaN)
54 #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
55 #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
56 #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
59 /* Macros for accessing decimal32 fields. These assume the argument
60 is a reference (pointer) to the decimal32 structure */
62 #define decimal32Sign(d) ((unsigned)(d)->bytes[0]>>7)
64 /* Get combination field */
65 #define decimal32Comb(d) (((d)->bytes[0] & 0x7c)>>2)
67 /* Get exponent continuation [does not remove bias] */
68 #define decimal32ExpCon(d) ((((d)->bytes[0] & 0x03)<<4) \
69 | ((unsigned)(d)->bytes[1]>>4))
71 /* Set sign [this assumes sign previously 0] */
72 #define decimal32SetSign(d, b) { \
73 (d)->bytes[0]|=((unsigned)(b)<<7);}
75 /* Set exponent continuation [does not apply bias] */
76 /* This assumes range has been checked and exponent previously 0; */
77 /* type of exponent must be unsigned */
78 #define decimal32SetExpCon(d, e) { \
79 (d)->bytes[0]|=(uint8_t)((e)>>4); \
80 (d)->bytes[1]|=(uint8_t)(((e)&0x0F)<<4);}
82 /* ------------------------------------------------------------------ */
84 /* ------------------------------------------------------------------ */
87 #define decimal32FromString __decimal32FromString
88 #define decimal32ToString __decimal32ToString
89 #define decimal32ToEngString __decimal32ToEngString
90 #define decimal32FromNumber __decimal32FromNumber
91 #define decimal32ToNumber __decimal32ToNumber
94 /* String conversions. */
95 decimal32
*decimal32FromString (decimal32
*, char *, decContext
*);
96 char *decimal32ToString (decimal32
*, char *);
97 char *decimal32ToEngString (decimal32
*, char *);
99 /* decNumber conversions. */
100 decimal32
*decimal32FromNumber (decimal32
*, decNumber
*, decContext
*);
101 decNumber
*decimal32ToNumber (decimal32
*, decNumber
*);