OSDN Git Service

a6bc87bb4a3ac39df249796bd7d3e0a042e1ee16
[pf3gnuchains/gcc-fork.git] / libdecnumber / dpd / decimal128.h
1 /* Decimal 128-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.
4
5    This file is part of GCC.
6
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
10    version.
11
12    In addition to the permissions in the GNU General Public License,
13    the Free Software Foundation gives you unlimited permission to link
14    the compiled version of this file into combinations with other
15    programs, and to distribute those combinations without any
16    restriction coming from the use of this file.  (The General Public
17    License restrictions do apply in other respects; for example, they
18    cover modification of the file, and distribution when not linked
19    into a combine executable.)
20
21    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
22    WARRANTY; without even the implied warranty of MERCHANTABILITY or
23    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24    for more details.
25
26    You should have received a copy of the GNU General Public License
27    along with GCC; see the file COPYING.  If not, write to the Free
28    Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29    02110-1301, USA.  */
30
31 #if !defined(DECIMAL128)
32 #define DECIMAL128
33 #define DEC128NAME     "decimal128"     /* Short name */
34 #define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */
35 #define DEC128AUTHOR   "Mike Cowlishaw" /* Who to blame */
36
37 #if defined(DECIMAL32)
38 #error decimal128.h must precede decimal32.h for correct DECNUMDIGITS
39 #else
40 #if defined(DECIMAL64)
41 #error decimal128.h must precede decimal64.h for correct DECNUMDIGITS
42 #endif
43 #endif
44
45   /* parameters for decimal128s */
46 #define DECIMAL128_Bytes  16    /* length */
47 #define DECIMAL128_Pmax   34    /* maximum precision (digits) */
48 #define DECIMAL128_Emax   6144  /* maximum adjusted exponent */
49 #define DECIMAL128_Emin  -6143  /* minimum adjusted exponent */
50 #define DECIMAL128_Bias   6176  /* bias for the exponent */
51 #define DECIMAL128_String 43    /* maximum string length, +1 */
52   /* highest biased exponent (Elimit-1) */
53 #define DECIMAL128_Ehigh  (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1)
54
55 #ifndef DECNUMDIGITS
56 #define DECNUMDIGITS DECIMAL128_Pmax    /* size if not already defined */
57 #endif
58 #ifndef DECNUMBER
59 #include "decNumber.h"          /* context and number library */
60 #endif
61
62   /* Decimal 128-bit type, accessible by bytes */
63 typedef struct
64 {
65   uint8_t bytes[DECIMAL128_Bytes];      /* decimal128: 1, 5, 12, 110 bits */
66 } decimal128;
67
68   /* special values [top byte excluding sign bit; last two bits are
69      don't-care for Infinity on input, last bit don't-care for NaN] */
70 #if !defined(DECIMAL_NaN)
71 #define DECIMAL_NaN     0x7c    /* 0 11111 00 NaN */
72 #define DECIMAL_sNaN    0x7e    /* 0 11111 10 sNaN */
73 #define DECIMAL_Inf     0x78    /* 0 11110 00 Infinity */
74 #endif
75
76   /* Macros for accessing decimal128 fields.  These assume the argument
77      is a reference (pointer) to the decimal128 structure */
78   /* Get sign */
79 #define decimal128Sign(d)       ((unsigned)(d)->bytes[0]>>7)
80
81   /* Get combination field */
82 #define decimal128Comb(d)       (((d)->bytes[0] & 0x7c)>>2)
83
84   /* Get exponent continuation [does not remove bias] */
85 #define decimal128ExpCon(d)     ((((d)->bytes[0] & 0x03)<<10)       \
86                                 | ((unsigned)(d)->bytes[1]<<2)        \
87                                 | ((unsigned)(d)->bytes[2]>>6))
88
89   /* Set sign [this assumes sign previously 0] */
90 #define decimal128SetSign(d, b) {                                   \
91     (d)->bytes[0]|=((unsigned)(b)<<7);}
92
93   /* Clear sign */
94 #define decimal128ClearSign(d) {(d)->bytes[0]&=~0x80;}
95
96   /* Flip sign */
97 #define decimal128FlipSign(d) {(d)->bytes[0]^=0x80;}
98
99   /* Set exponent continuation [does not apply bias] */
100   /* This assumes range has been checked and exponent previously 0; */
101   /* type of exponent must be unsigned */
102 #define decimal128SetExpCon(d, e) {                                 \
103     (d)->bytes[0]|=(uint8_t)((e)>>10);                                \
104     (d)->bytes[1] =(uint8_t)(((e)&0x3fc)>>2);                         \
105     (d)->bytes[2]|=(uint8_t)(((e)&0x03)<<6);}
106
107   /* ------------------------------------------------------------------ */
108   /* Routines                                                           */
109   /* ------------------------------------------------------------------ */
110
111 #ifdef IN_LIBGCC2
112 #ifndef decimal128FromString
113 #define decimal128FromString __decimal128FromString
114 #define decimal128ToString __decimal128ToString
115 #define decimal128ToEngString __decimal128ToEngString
116 #define decimal128FromNumber __decimal128FromNumber
117 #define decimal128ToNumber __decimal128ToNumber
118 #endif
119 #endif
120
121   /* String conversions */
122 decimal128 *decimal128FromString (decimal128 *, const char *, decContext *);
123 char *decimal128ToString (const decimal128 *, char *);
124 char *decimal128ToEngString (const decimal128 *, char *);
125
126   /* decNumber conversions */
127 decimal128 *decimal128FromNumber (decimal128 *, const decNumber *, decContext *);
128 decNumber *decimal128ToNumber (const decimal128 *, decNumber *);
129
130 #endif