OSDN Git Service

2007-09-10 Janis Johnson <janis187@us.ibm.com>
[pf3gnuchains/gcc-fork.git] / libdecnumber / dpd / decimal64.h
1 /* Decimal 64-bit format module header for the decNumber C Library.
2    Copyright (C) 2005, 2007 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 /* ------------------------------------------------------------------ */
32 /* Decimal 64-bit format module header                                */
33 /* ------------------------------------------------------------------ */
34
35 #if !defined(DECIMAL64)
36   #define DECIMAL64
37   #define DEC64NAME     "decimal64"                   /* Short name   */
38   #define DEC64FULLNAME "Decimal 64-bit Number"       /* Verbose name */
39   #define DEC64AUTHOR   "Mike Cowlishaw"              /* Who to blame */
40
41
42   /* parameters for decimal64s                                        */
43   #define DECIMAL64_Bytes  8            /* length                     */
44   #define DECIMAL64_Pmax   16           /* maximum precision (digits) */
45   #define DECIMAL64_Emax   384          /* maximum adjusted exponent  */
46   #define DECIMAL64_Emin  -383          /* minimum adjusted exponent  */
47   #define DECIMAL64_Bias   398          /* bias for the exponent      */
48   #define DECIMAL64_String 24           /* maximum string length, +1  */
49   #define DECIMAL64_EconL  8            /* exp. continuation length   */
50   /* highest biased exponent (Elimit-1)                               */
51   #define DECIMAL64_Ehigh  (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1)
52
53   /* check enough digits, if pre-defined                              */
54   #if defined(DECNUMDIGITS)
55     #if (DECNUMDIGITS<DECIMAL64_Pmax)
56       #error decimal64.h needs pre-defined DECNUMDIGITS>=16 for safe use
57     #endif
58   #endif
59
60
61   #ifndef DECNUMDIGITS
62     #define DECNUMDIGITS DECIMAL64_Pmax /* size if not already defined*/
63   #endif
64   #ifndef DECNUMBER
65     #include "decNumber.h"              /* context and number library */
66   #endif
67
68   /* Decimal 64-bit type, accessible by bytes                         */
69   typedef struct {
70     uint8_t bytes[DECIMAL64_Bytes];     /* decimal64: 1, 5, 8, 50 bits*/
71     } decimal64;
72
73   /* special values [top byte excluding sign bit; last two bits are   */
74   /* don't-care for Infinity on input, last bit don't-care for NaN]   */
75   #if !defined(DECIMAL_NaN)
76     #define DECIMAL_NaN     0x7c        /* 0 11111 00 NaN             */
77     #define DECIMAL_sNaN    0x7e        /* 0 11111 10 sNaN            */
78     #define DECIMAL_Inf     0x78        /* 0 11110 00 Infinity        */
79   #endif
80
81   /* ---------------------------------------------------------------- */
82   /* Routines                                                         */
83   /* ---------------------------------------------------------------- */
84
85   #include "decimal64Symbols.h"
86
87   /* String conversions                                               */
88   decimal64 * decimal64FromString(decimal64 *, const char *, decContext *);
89   char * decimal64ToString(const decimal64 *, char *);
90   char * decimal64ToEngString(const decimal64 *, char *);
91
92   /* decNumber conversions                                            */
93   decimal64 * decimal64FromNumber(decimal64 *, const decNumber *,
94                                   decContext *);
95   decNumber * decimal64ToNumber(const decimal64 *, decNumber *);
96
97   /* Format-dependent utilities                                       */
98   uint32_t    decimal64IsCanonical(const decimal64 *);
99   decimal64 * decimal64Canonical(decimal64 *, const decimal64 *);
100
101 #endif