1169695Skan/* Decimal 32-bit format module header for the decNumber C Library
2169695Skan   Copyright (C) 2005 Free Software Foundation, Inc.
3169695Skan   Contributed by IBM Corporation.  Author Mike Cowlishaw.
4169695Skan
5169695Skan   This file is part of GCC.
6169695Skan
7169695Skan   GCC is free software; you can redistribute it and/or modify it under
8169695Skan   the terms of the GNU General Public License as published by the Free
9169695Skan   Software Foundation; either version 2, or (at your option) any later
10169695Skan   version.
11169695Skan
12169695Skan   In addition to the permissions in the GNU General Public License,
13169695Skan   the Free Software Foundation gives you unlimited permission to link
14169695Skan   the compiled version of this file into combinations with other
15169695Skan   programs, and to distribute those combinations without any
16169695Skan   restriction coming from the use of this file.  (The General Public
17169695Skan   License restrictions do apply in other respects; for example, they
18169695Skan   cover modification of the file, and distribution when not linked
19169695Skan   into a combine executable.)
20169695Skan
21169695Skan   GCC is distributed in the hope that it will be useful, but WITHOUT ANY
22169695Skan   WARRANTY; without even the implied warranty of MERCHANTABILITY or
23169695Skan   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24169695Skan   for more details.
25169695Skan
26169695Skan   You should have received a copy of the GNU General Public License
27169695Skan   along with GCC; see the file COPYING.  If not, write to the Free
28169695Skan   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29169695Skan   02110-1301, USA.  */
30169695Skan
31169695Skan#if !defined(DECIMAL32)
32169695Skan#define DECIMAL32
33169695Skan#define DEC32NAME     "decimal32"	/* Short name */
34169695Skan#define DEC32FULLNAME "Decimal 32-bit Number"	/* Verbose name */
35169695Skan#define DEC32AUTHOR   "Mike Cowlishaw"	/* Who to blame */
36169695Skan
37169695Skan  /* parameters for decimal32s */
38169695Skan#define DECIMAL32_Bytes  4	/* length */
39169695Skan#define DECIMAL32_Pmax   7	/* maximum precision (digits) */
40169695Skan#define DECIMAL32_Emax   96	/* maximum adjusted exponent */
41169695Skan#define DECIMAL32_Emin  -95	/* minimum adjusted exponent */
42169695Skan#define DECIMAL32_Bias   101	/* bias for the exponent */
43169695Skan#define DECIMAL32_String 15	/* maximum string length, +1 */
44169695Skan  /* highest biased exponent (Elimit-1) */
45169695Skan#define DECIMAL32_Ehigh  (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1)
46169695Skan
47169695Skan#ifndef DECNUMDIGITS
48169695Skan#define DECNUMDIGITS DECIMAL32_Pmax	/* size if not already defined */
49169695Skan#endif
50169695Skan#ifndef DECNUMBER
51169695Skan#include "decNumber.h"		/* context and number library */
52169695Skan#endif
53169695Skan
54169695Skan  /* Decimal 32-bit type, accessible by bytes */
55169695Skantypedef struct
56169695Skan{
57169695Skan  uint8_t bytes[DECIMAL32_Bytes];	/* decimal32: 1, 5, 6, 20 bits */
58169695Skan} decimal32;
59169695Skan
60169695Skan  /* special values [top byte excluding sign bit; last two bits are
61169695Skan     don't-care for Infinity on input, last bit don't-care for NaN] */
62169695Skan#if !defined(DECIMAL_NaN)
63169695Skan#define DECIMAL_NaN     0x7c	/* 0 11111 00 NaN */
64169695Skan#define DECIMAL_sNaN    0x7e	/* 0 11111 10 sNaN */
65169695Skan#define DECIMAL_Inf     0x78	/* 0 11110 00 Infinity */
66169695Skan#endif
67169695Skan
68169695Skan  /* Macros for accessing decimal32 fields.  These assume the argument
69169695Skan     is a reference (pointer) to the decimal32 structure */
70169695Skan  /* Get sign */
71169695Skan#define decimal32Sign(d)       ((unsigned)(d)->bytes[0]>>7)
72169695Skan
73169695Skan  /* Get combination field */
74169695Skan#define decimal32Comb(d)       (((d)->bytes[0] & 0x7c)>>2)
75169695Skan
76169695Skan  /* Get exponent continuation [does not remove bias] */
77169695Skan#define decimal32ExpCon(d)     ((((d)->bytes[0] & 0x03)<<4)         \
78169695Skan                               | ((unsigned)(d)->bytes[1]>>4))
79169695Skan
80169695Skan  /* Set sign [this assumes sign previously 0] */
81169695Skan#define decimal32SetSign(d, b) {                                    \
82169695Skan    (d)->bytes[0]|=((unsigned)(b)<<7);}
83169695Skan
84169695Skan  /* Set exponent continuation [does not apply bias] */
85169695Skan  /* This assumes range has been checked and exponent previously 0; */
86169695Skan  /* type of exponent must be unsigned */
87169695Skan#define decimal32SetExpCon(d, e) {                                  \
88169695Skan    (d)->bytes[0]|=(uint8_t)((e)>>4);                                 \
89169695Skan    (d)->bytes[1]|=(uint8_t)(((e)&0x0F)<<4);}
90169695Skan
91169695Skan  /* ------------------------------------------------------------------ */
92169695Skan  /* Routines                                                           */
93169695Skan  /* ------------------------------------------------------------------ */
94169695Skan
95169695Skan#ifdef IN_LIBGCC2
96169695Skan#define decimal32FromString __decimal32FromString
97169695Skan#define decimal32ToString __decimal32ToString
98169695Skan#define decimal32ToEngString __decimal32ToEngString
99169695Skan#define decimal32FromNumber __decimal32FromNumber
100169695Skan#define decimal32ToNumber __decimal32ToNumber
101169695Skan#endif
102169695Skan
103169695Skan/* String conversions.  */
104169695Skandecimal32 *decimal32FromString (decimal32 *, const char *, decContext *);
105169695Skanchar *decimal32ToString (const decimal32 *, char *);
106169695Skanchar *decimal32ToEngString (const decimal32 *, char *);
107169695Skan
108169695Skan/* decNumber conversions.  */
109169695Skandecimal32 *decimal32FromNumber (decimal32 *, const decNumber *, decContext *);
110169695SkandecNumber *decimal32ToNumber (const decimal32 *, decNumber *);
111169695Skan
112169695Skan#endif
113