xref: /qemu/include/libdecnumber/dpd/decimal64.h (revision 0f2d3732202818fb85c09d1c204a08c4d79b70bc)
172ac97cdSTom Musta /* Decimal 64-bit format module header for the decNumber C Library.
272ac97cdSTom Musta    Copyright (C) 2005, 2007 Free Software Foundation, Inc.
372ac97cdSTom Musta    Contributed by IBM Corporation.  Author Mike Cowlishaw.
472ac97cdSTom Musta 
572ac97cdSTom Musta    This file is part of GCC.
672ac97cdSTom Musta 
772ac97cdSTom Musta    GCC is free software; you can redistribute it and/or modify it under
872ac97cdSTom Musta    the terms of the GNU General Public License as published by the Free
972ac97cdSTom Musta    Software Foundation; either version 2, or (at your option) any later
1072ac97cdSTom Musta    version.
1172ac97cdSTom Musta 
1272ac97cdSTom Musta    In addition to the permissions in the GNU General Public License,
1372ac97cdSTom Musta    the Free Software Foundation gives you unlimited permission to link
1472ac97cdSTom Musta    the compiled version of this file into combinations with other
1572ac97cdSTom Musta    programs, and to distribute those combinations without any
1672ac97cdSTom Musta    restriction coming from the use of this file.  (The General Public
1772ac97cdSTom Musta    License restrictions do apply in other respects; for example, they
1872ac97cdSTom Musta    cover modification of the file, and distribution when not linked
1972ac97cdSTom Musta    into a combine executable.)
2072ac97cdSTom Musta 
2172ac97cdSTom Musta    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
2272ac97cdSTom Musta    WARRANTY; without even the implied warranty of MERCHANTABILITY or
2372ac97cdSTom Musta    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2472ac97cdSTom Musta    for more details.
2572ac97cdSTom Musta 
2672ac97cdSTom Musta    You should have received a copy of the GNU General Public License
2772ac97cdSTom Musta    along with GCC; see the file COPYING.  If not, write to the Free
2872ac97cdSTom Musta    Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
2972ac97cdSTom Musta    02110-1301, USA.  */
3072ac97cdSTom Musta 
3172ac97cdSTom Musta /* ------------------------------------------------------------------ */
3272ac97cdSTom Musta /* Decimal 64-bit format module header				      */
3372ac97cdSTom Musta /* ------------------------------------------------------------------ */
3472ac97cdSTom Musta 
3572ac97cdSTom Musta #if !defined(DECIMAL64)
3672ac97cdSTom Musta   #define DECIMAL64
3772ac97cdSTom Musta   #define DEC64NAME	"decimal64"		      /* Short name   */
3872ac97cdSTom Musta   #define DEC64FULLNAME "Decimal 64-bit Number"	      /* Verbose name */
3972ac97cdSTom Musta   #define DEC64AUTHOR	"Mike Cowlishaw"	      /* Who to blame */
4072ac97cdSTom Musta 
4172ac97cdSTom Musta 
4272ac97cdSTom Musta   /* parameters for decimal64s					      */
4372ac97cdSTom Musta   #define DECIMAL64_Bytes  8		/* length		      */
4472ac97cdSTom Musta   #define DECIMAL64_Pmax   16		/* maximum precision (digits) */
4572ac97cdSTom Musta   #define DECIMAL64_Emax   384		/* maximum adjusted exponent  */
4672ac97cdSTom Musta   #define DECIMAL64_Emin  -383		/* minimum adjusted exponent  */
4772ac97cdSTom Musta   #define DECIMAL64_Bias   398		/* bias for the exponent      */
4872ac97cdSTom Musta   #define DECIMAL64_String 24		/* maximum string length, +1  */
4972ac97cdSTom Musta   #define DECIMAL64_EconL  8		/* exp. continuation length   */
5072ac97cdSTom Musta   /* highest biased exponent (Elimit-1)				      */
5172ac97cdSTom Musta   #define DECIMAL64_Ehigh  (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1)
5272ac97cdSTom Musta 
5372ac97cdSTom Musta   /* check enough digits, if pre-defined			      */
5472ac97cdSTom Musta   #if defined(DECNUMDIGITS)
5572ac97cdSTom Musta     #if (DECNUMDIGITS<DECIMAL64_Pmax)
5672ac97cdSTom Musta       #error decimal64.h needs pre-defined DECNUMDIGITS>=16 for safe use
5772ac97cdSTom Musta     #endif
5872ac97cdSTom Musta   #endif
5972ac97cdSTom Musta 
6072ac97cdSTom Musta 
6172ac97cdSTom Musta   #ifndef DECNUMDIGITS
6272ac97cdSTom Musta     #define DECNUMDIGITS DECIMAL64_Pmax /* size if not already defined*/
6372ac97cdSTom Musta   #endif
6472ac97cdSTom Musta   #ifndef DECNUMBER
65*0f2d3732STom Musta     #include "libdecnumber/decNumber.h"
6672ac97cdSTom Musta   #endif
6772ac97cdSTom Musta 
6872ac97cdSTom Musta   /* Decimal 64-bit type, accessible by bytes			      */
6972ac97cdSTom Musta   typedef struct {
7072ac97cdSTom Musta     uint8_t bytes[DECIMAL64_Bytes];	/* decimal64: 1, 5, 8, 50 bits*/
7172ac97cdSTom Musta     } decimal64;
7272ac97cdSTom Musta 
7372ac97cdSTom Musta   /* special values [top byte excluding sign bit; last two bits are   */
7472ac97cdSTom Musta   /* don't-care for Infinity on input, last bit don't-care for NaN]   */
7572ac97cdSTom Musta   #if !defined(DECIMAL_NaN)
7672ac97cdSTom Musta     #define DECIMAL_NaN	    0x7c	/* 0 11111 00 NaN	      */
7772ac97cdSTom Musta     #define DECIMAL_sNaN    0x7e	/* 0 11111 10 sNaN	      */
7872ac97cdSTom Musta     #define DECIMAL_Inf	    0x78	/* 0 11110 00 Infinity	      */
7972ac97cdSTom Musta   #endif
8072ac97cdSTom Musta 
8172ac97cdSTom Musta   /* ---------------------------------------------------------------- */
8272ac97cdSTom Musta   /* Routines							      */
8372ac97cdSTom Musta   /* ---------------------------------------------------------------- */
8472ac97cdSTom Musta 
8572ac97cdSTom Musta 
8672ac97cdSTom Musta   /* String conversions						      */
8772ac97cdSTom Musta   decimal64 * decimal64FromString(decimal64 *, const char *, decContext *);
8872ac97cdSTom Musta   char * decimal64ToString(const decimal64 *, char *);
8972ac97cdSTom Musta   char * decimal64ToEngString(const decimal64 *, char *);
9072ac97cdSTom Musta 
9172ac97cdSTom Musta   /* decNumber conversions					      */
9272ac97cdSTom Musta   decimal64 * decimal64FromNumber(decimal64 *, const decNumber *,
9372ac97cdSTom Musta 				  decContext *);
9472ac97cdSTom Musta   decNumber * decimal64ToNumber(const decimal64 *, decNumber *);
9572ac97cdSTom Musta 
9672ac97cdSTom Musta   /* Format-dependent utilities					      */
9772ac97cdSTom Musta   uint32_t    decimal64IsCanonical(const decimal64 *);
9872ac97cdSTom Musta   decimal64 * decimal64Canonical(decimal64 *, const decimal64 *);
9972ac97cdSTom Musta 
10072ac97cdSTom Musta #endif
101