Some build script code cleaning and environment change for one of slave builders.
[llvm-gcc-4.2.git] / libdecnumber / decimal128.h
blobbcc75a12bd6944c73a66d5f44712fc999f3b70c8
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.
5 This file is part of GCC.
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.
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.)
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.
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. */
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 */
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
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)
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
62 /* Decimal 128-bit type, accessible by bytes */
63 typedef struct
65 uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits */
66 } decimal128;
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
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)
81 /* Get combination field */
82 #define decimal128Comb(d) (((d)->bytes[0] & 0x7c)>>2)
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))
89 /* Set sign [this assumes sign previously 0] */
90 #define decimal128SetSign(d, b) { \
91 (d)->bytes[0]|=((unsigned)(b)<<7);}
93 /* Set exponent continuation [does not apply bias] */
94 /* This assumes range has been checked and exponent previously 0; */
95 /* type of exponent must be unsigned */
96 #define decimal128SetExpCon(d, e) { \
97 (d)->bytes[0]|=(uint8_t)((e)>>10); \
98 (d)->bytes[1] =(uint8_t)(((e)&0x3fc)>>2); \
99 (d)->bytes[2]|=(uint8_t)(((e)&0x03)<<6);}
101 /* ------------------------------------------------------------------ */
102 /* Routines */
103 /* ------------------------------------------------------------------ */
105 #ifdef IN_LIBGCC2
106 #define decimal128FromString __decimal128FromString
107 #define decimal128ToString __decimal128ToString
108 #define decimal128ToEngString __decimal128ToEngString
109 #define decimal128FromNumber __decimal128FromNumber
110 #define decimal128ToNumber __decimal128ToNumber
111 #endif
113 /* String conversions */
114 decimal128 *decimal128FromString (decimal128 *, const char *, decContext *);
115 char *decimal128ToString (const decimal128 *, char *);
116 char *decimal128ToEngString (const decimal128 *, char *);
118 /* decNumber conversions */
119 decimal128 *decimal128FromNumber (decimal128 *, const decNumber *, decContext *);
120 decNumber *decimal128ToNumber (const decimal128 *, decNumber *);
122 #endif