1169695Skan/* Decimal 64-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(DECIMAL64)
32169695Skan#define DECIMAL64
33169695Skan#define DEC64NAME     "decimal64"	/* Short name */
34169695Skan#define DEC64FULLNAME "Decimal 64-bit Number"	/* Verbose name */
35169695Skan#define DEC64AUTHOR   "Mike Cowlishaw"	/* Who to blame */
36169695Skan
37169695Skan#if defined(DECIMAL32)
38169695Skan#error decimal64.h must precede decimal32.h for correct DECNUMDIGITS
39169695Skan#endif
40169695Skan
41169695Skan  /* parameters for decimal64s */
42169695Skan#define DECIMAL64_Bytes  8	/* length */
43169695Skan#define DECIMAL64_Pmax   16	/* maximum precision (digits) */
44169695Skan#define DECIMAL64_Emax   384	/* maximum adjusted exponent */
45169695Skan#define DECIMAL64_Emin  -383	/* minimum adjusted exponent */
46169695Skan#define DECIMAL64_Bias   398	/* bias for the exponent */
47169695Skan#define DECIMAL64_String 24	/* maximum string length, +1 */
48169695Skan  /* highest biased exponent (Elimit-1) */
49169695Skan#define DECIMAL64_Ehigh  (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1)
50169695Skan
51169695Skan#ifndef DECNUMDIGITS
52169695Skan#define DECNUMDIGITS DECIMAL64_Pmax	/* size if not already defined */
53169695Skan#endif
54169695Skan#ifndef DECNUMBER
55169695Skan#include "decNumber.h"		/* context and number library */
56169695Skan#endif
57169695Skan
58169695Skan  /* Decimal 64-bit type, accessible by bytes */
59169695Skantypedef struct
60169695Skan{
61169695Skan  uint8_t bytes[DECIMAL64_Bytes];	/* decimal64: 1, 5, 8, 50 bits */
62169695Skan} decimal64;
63169695Skan
64169695Skan  /* special values [top byte excluding sign bit; last two bits are
65169695Skan     don't-care for Infinity on input, last bit don't-care for NaN] */
66169695Skan#if !defined(DECIMAL_NaN)
67169695Skan#define DECIMAL_NaN     0x7c	/* 0 11111 00 NaN */
68169695Skan#define DECIMAL_sNaN    0x7e	/* 0 11111 10 sNaN */
69169695Skan#define DECIMAL_Inf     0x78	/* 0 11110 00 Infinity */
70169695Skan#endif
71169695Skan
72169695Skan  /* Macros for accessing decimal64 fields.  These assume the argument
73169695Skan     is a reference (pointer) to the decimal64 structure */
74169695Skan  /* Get sign */
75169695Skan#define decimal64Sign(d)       ((unsigned)(d)->bytes[0]>>7)
76169695Skan
77169695Skan  /* Get combination field */
78169695Skan#define decimal64Comb(d)       (((d)->bytes[0] & 0x7c)>>2)
79169695Skan
80169695Skan  /* Get exponent continuation [does not remove bias] */
81169695Skan#define decimal64ExpCon(d)     ((((d)->bytes[0] & 0x03)<<6)         \
82169695Skan                               | ((unsigned)(d)->bytes[1]>>2))
83169695Skan
84169695Skan  /* Set sign [this assumes sign previously 0] */
85169695Skan#define decimal64SetSign(d, b) {                                    \
86169695Skan    (d)->bytes[0]|=((unsigned)(b)<<7);}
87169695Skan
88169695Skan  /* Set exponent continuation [does not apply bias] */
89169695Skan  /* This assumes range has been checked and exponent previously 0; type */
90169695Skan  /* of exponent must be unsigned */
91169695Skan#define decimal64SetExpCon(d, e) {                                  \
92169695Skan    (d)->bytes[0]|=(uint8_t)((e)>>6);                                 \
93169695Skan    (d)->bytes[1]|=(uint8_t)(((e)&0x3F)<<2);}
94169695Skan
95169695Skan  /* ------------------------------------------------------------------ */
96169695Skan  /* Routines                                                           */
97169695Skan  /* ------------------------------------------------------------------ */
98169695Skan
99169695Skan#ifdef IN_LIBGCC2
100169695Skan#define decimal64FromString __decimal64FromString
101169695Skan#define decimal64ToString __decimal64ToString
102169695Skan#define decimal64ToEngString __decimal64ToEngString
103169695Skan#define decimal64FromNumber __decimal64FromNumber
104169695Skan#define decimal64ToNumber __decimal64ToNumber
105169695Skan#endif
106169695Skan
107169695Skan  /* String conversions */
108169695Skandecimal64 *decimal64FromString (decimal64 *, const char *, decContext *);
109169695Skanchar *decimal64ToString (const decimal64 *, char *);
110169695Skanchar *decimal64ToEngString (const decimal64 *, char *);
111169695Skan
112169695Skan  /* decNumber conversions */
113169695Skandecimal64 *decimal64FromNumber (decimal64 *, const decNumber *, decContext *);
114169695SkandecNumber *decimal64ToNumber (const decimal64 *, decNumber *);
115169695Skan
116169695Skan#endif
117