xref: /openbsd/gnu/gcc/libdecnumber/decimal64.h (revision 404b540a)
1*404b540aSrobert /* Decimal 64-bit format module header for the decNumber C Library
2*404b540aSrobert    Copyright (C) 2005 Free Software Foundation, Inc.
3*404b540aSrobert    Contributed by IBM Corporation.  Author Mike Cowlishaw.
4*404b540aSrobert 
5*404b540aSrobert    This file is part of GCC.
6*404b540aSrobert 
7*404b540aSrobert    GCC is free software; you can redistribute it and/or modify it under
8*404b540aSrobert    the terms of the GNU General Public License as published by the Free
9*404b540aSrobert    Software Foundation; either version 2, or (at your option) any later
10*404b540aSrobert    version.
11*404b540aSrobert 
12*404b540aSrobert    In addition to the permissions in the GNU General Public License,
13*404b540aSrobert    the Free Software Foundation gives you unlimited permission to link
14*404b540aSrobert    the compiled version of this file into combinations with other
15*404b540aSrobert    programs, and to distribute those combinations without any
16*404b540aSrobert    restriction coming from the use of this file.  (The General Public
17*404b540aSrobert    License restrictions do apply in other respects; for example, they
18*404b540aSrobert    cover modification of the file, and distribution when not linked
19*404b540aSrobert    into a combine executable.)
20*404b540aSrobert 
21*404b540aSrobert    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
22*404b540aSrobert    WARRANTY; without even the implied warranty of MERCHANTABILITY or
23*404b540aSrobert    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24*404b540aSrobert    for more details.
25*404b540aSrobert 
26*404b540aSrobert    You should have received a copy of the GNU General Public License
27*404b540aSrobert    along with GCC; see the file COPYING.  If not, write to the Free
28*404b540aSrobert    Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29*404b540aSrobert    02110-1301, USA.  */
30*404b540aSrobert 
31*404b540aSrobert #if !defined(DECIMAL64)
32*404b540aSrobert #define DECIMAL64
33*404b540aSrobert #define DEC64NAME     "decimal64"	/* Short name */
34*404b540aSrobert #define DEC64FULLNAME "Decimal 64-bit Number"	/* Verbose name */
35*404b540aSrobert #define DEC64AUTHOR   "Mike Cowlishaw"	/* Who to blame */
36*404b540aSrobert 
37*404b540aSrobert #if defined(DECIMAL32)
38*404b540aSrobert #error decimal64.h must precede decimal32.h for correct DECNUMDIGITS
39*404b540aSrobert #endif
40*404b540aSrobert 
41*404b540aSrobert   /* parameters for decimal64s */
42*404b540aSrobert #define DECIMAL64_Bytes  8	/* length */
43*404b540aSrobert #define DECIMAL64_Pmax   16	/* maximum precision (digits) */
44*404b540aSrobert #define DECIMAL64_Emax   384	/* maximum adjusted exponent */
45*404b540aSrobert #define DECIMAL64_Emin  -383	/* minimum adjusted exponent */
46*404b540aSrobert #define DECIMAL64_Bias   398	/* bias for the exponent */
47*404b540aSrobert #define DECIMAL64_String 24	/* maximum string length, +1 */
48*404b540aSrobert   /* highest biased exponent (Elimit-1) */
49*404b540aSrobert #define DECIMAL64_Ehigh  (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1)
50*404b540aSrobert 
51*404b540aSrobert #ifndef DECNUMDIGITS
52*404b540aSrobert #define DECNUMDIGITS DECIMAL64_Pmax	/* size if not already defined */
53*404b540aSrobert #endif
54*404b540aSrobert #ifndef DECNUMBER
55*404b540aSrobert #include "decNumber.h"		/* context and number library */
56*404b540aSrobert #endif
57*404b540aSrobert 
58*404b540aSrobert   /* Decimal 64-bit type, accessible by bytes */
59*404b540aSrobert typedef struct
60*404b540aSrobert {
61*404b540aSrobert   uint8_t bytes[DECIMAL64_Bytes];	/* decimal64: 1, 5, 8, 50 bits */
62*404b540aSrobert } decimal64;
63*404b540aSrobert 
64*404b540aSrobert   /* special values [top byte excluding sign bit; last two bits are
65*404b540aSrobert      don't-care for Infinity on input, last bit don't-care for NaN] */
66*404b540aSrobert #if !defined(DECIMAL_NaN)
67*404b540aSrobert #define DECIMAL_NaN     0x7c	/* 0 11111 00 NaN */
68*404b540aSrobert #define DECIMAL_sNaN    0x7e	/* 0 11111 10 sNaN */
69*404b540aSrobert #define DECIMAL_Inf     0x78	/* 0 11110 00 Infinity */
70*404b540aSrobert #endif
71*404b540aSrobert 
72*404b540aSrobert   /* Macros for accessing decimal64 fields.  These assume the argument
73*404b540aSrobert      is a reference (pointer) to the decimal64 structure */
74*404b540aSrobert   /* Get sign */
75*404b540aSrobert #define decimal64Sign(d)       ((unsigned)(d)->bytes[0]>>7)
76*404b540aSrobert 
77*404b540aSrobert   /* Get combination field */
78*404b540aSrobert #define decimal64Comb(d)       (((d)->bytes[0] & 0x7c)>>2)
79*404b540aSrobert 
80*404b540aSrobert   /* Get exponent continuation [does not remove bias] */
81*404b540aSrobert #define decimal64ExpCon(d)     ((((d)->bytes[0] & 0x03)<<6)         \
82*404b540aSrobert                                | ((unsigned)(d)->bytes[1]>>2))
83*404b540aSrobert 
84*404b540aSrobert   /* Set sign [this assumes sign previously 0] */
85*404b540aSrobert #define decimal64SetSign(d, b) {                                    \
86*404b540aSrobert     (d)->bytes[0]|=((unsigned)(b)<<7);}
87*404b540aSrobert 
88*404b540aSrobert   /* Set exponent continuation [does not apply bias] */
89*404b540aSrobert   /* This assumes range has been checked and exponent previously 0; type */
90*404b540aSrobert   /* of exponent must be unsigned */
91*404b540aSrobert #define decimal64SetExpCon(d, e) {                                  \
92*404b540aSrobert     (d)->bytes[0]|=(uint8_t)((e)>>6);                                 \
93*404b540aSrobert     (d)->bytes[1]|=(uint8_t)(((e)&0x3F)<<2);}
94*404b540aSrobert 
95*404b540aSrobert   /* ------------------------------------------------------------------ */
96*404b540aSrobert   /* Routines                                                           */
97*404b540aSrobert   /* ------------------------------------------------------------------ */
98*404b540aSrobert 
99*404b540aSrobert #ifdef IN_LIBGCC2
100*404b540aSrobert #define decimal64FromString __decimal64FromString
101*404b540aSrobert #define decimal64ToString __decimal64ToString
102*404b540aSrobert #define decimal64ToEngString __decimal64ToEngString
103*404b540aSrobert #define decimal64FromNumber __decimal64FromNumber
104*404b540aSrobert #define decimal64ToNumber __decimal64ToNumber
105*404b540aSrobert #endif
106*404b540aSrobert 
107*404b540aSrobert   /* String conversions */
108*404b540aSrobert decimal64 *decimal64FromString (decimal64 *, const char *, decContext *);
109*404b540aSrobert char *decimal64ToString (const decimal64 *, char *);
110*404b540aSrobert char *decimal64ToEngString (const decimal64 *, char *);
111*404b540aSrobert 
112*404b540aSrobert   /* decNumber conversions */
113*404b540aSrobert decimal64 *decimal64FromNumber (decimal64 *, const decNumber *, decContext *);
114*404b540aSrobert decNumber *decimal64ToNumber (const decimal64 *, decNumber *);
115*404b540aSrobert 
116*404b540aSrobert #endif
117