OSDN Git Service

* Makefile.in: Don't include decRound in library used by compiler.
[pf3gnuchains/gcc-fork.git] / libdecnumber / 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    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
15    for more details.
16
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
20    02110-1301, USA.  */
21
22 #if !defined(DECIMAL128)
23 #define DECIMAL128
24 #define DEC128NAME     "decimal128"     /* Short name */
25 #define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */
26 #define DEC128AUTHOR   "Mike Cowlishaw" /* Who to blame */
27
28 #if defined(DECIMAL32)
29 #error decimal128.h must precede decimal32.h for correct DECNUMDIGITS
30 #else
31 #if defined(DECIMAL64)
32 #error decimal128.h must precede decimal64.h for correct DECNUMDIGITS
33 #endif
34 #endif
35
36   /* parameters for decimal128s */
37 #define DECIMAL128_Bytes  16    /* length */
38 #define DECIMAL128_Pmax   34    /* maximum precision (digits) */
39 #define DECIMAL128_Emax   6144  /* maximum adjusted exponent */
40 #define DECIMAL128_Emin  -6143  /* minimum adjusted exponent */
41 #define DECIMAL128_Bias   6176  /* bias for the exponent */
42 #define DECIMAL128_String 43    /* maximum string length, +1 */
43   /* highest biased exponent (Elimit-1) */
44 #define DECIMAL128_Ehigh  (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1)
45
46 #ifndef DECNUMDIGITS
47 #define DECNUMDIGITS DECIMAL128_Pmax    /* size if not already defined */
48 #endif
49 #ifndef DECNUMBER
50 #include "decNumber.h"          /* context and number library */
51 #endif
52
53   /* Decimal 128-bit type, accessible by bytes */
54 typedef struct
55 {
56   uint8_t bytes[DECIMAL128_Bytes];      /* decimal128: 1, 5, 12, 110 bits */
57 } decimal128;
58
59   /* special values [top byte excluding sign bit; last two bits are
60      don't-care for Infinity on input, last bit don't-care for NaN] */
61 #if !defined(DECIMAL_NaN)
62 #define DECIMAL_NaN     0x7c    /* 0 11111 00 NaN */
63 #define DECIMAL_sNaN    0x7e    /* 0 11111 10 sNaN */
64 #define DECIMAL_Inf     0x78    /* 0 11110 00 Infinity */
65 #endif
66
67   /* Macros for accessing decimal128 fields.  These assume the argument
68      is a reference (pointer) to the decimal128 structure */
69   /* Get sign */
70 #define decimal128Sign(d)       ((unsigned)(d)->bytes[0]>>7)
71
72   /* Get combination field */
73 #define decimal128Comb(d)       (((d)->bytes[0] & 0x7c)>>2)
74
75   /* Get exponent continuation [does not remove bias] */
76 #define decimal128ExpCon(d)     ((((d)->bytes[0] & 0x03)<<10)       \
77                                 | ((unsigned)(d)->bytes[1]<<2)        \
78                                 | ((unsigned)(d)->bytes[2]>>6))
79
80   /* Set sign [this assumes sign previously 0] */
81 #define decimal128SetSign(d, b) {                                   \
82     (d)->bytes[0]|=((unsigned)(b)<<7);}
83
84   /* Set exponent continuation [does not apply bias] */
85   /* This assumes range has been checked and exponent previously 0; */
86   /* type of exponent must be unsigned */
87 #define decimal128SetExpCon(d, e) {                                 \
88     (d)->bytes[0]|=(uint8_t)((e)>>10);                                \
89     (d)->bytes[1] =(uint8_t)(((e)&0x3fc)>>2);                         \
90     (d)->bytes[2]|=(uint8_t)(((e)&0x03)<<6);}
91
92   /* ------------------------------------------------------------------ */
93   /* Routines                                                           */
94   /* ------------------------------------------------------------------ */
95
96 #ifdef IN_LIBGCC2
97 #define decimal128FromString __decimal128FromString
98 #define decimal128ToString __decimal128ToString
99 #define decimal128ToEngString __decimal128ToEngString
100 #define decimal128FromNumber __decimal128FromNumber
101 #define decimal128ToNumber __decimal128ToNumber
102 #endif
103
104   /* String conversions */
105 decimal128 *decimal128FromString (decimal128 *, const char *, decContext *);
106 char *decimal128ToString (const decimal128 *, char *);
107 char *decimal128ToEngString (const decimal128 *, char *);
108
109   /* decNumber conversions */
110 decimal128 *decimal128FromNumber (decimal128 *, const decNumber *, decContext *);
111 decNumber *decimal128ToNumber (const decimal128 *, decNumber *);
112
113 #endif