xref: /dflybsd-src/contrib/gdb-7/libdecnumber/dpd/decimal128.h (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Decimal 128-bit format module header for the decNumber C Library.
2*ef5ccd6cSJohn Marino    Copyright (C) 2005-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert    Contributed by IBM Corporation.  Author Mike Cowlishaw.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GCC.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    GCC is free software; you can redistribute it and/or modify it under
85796c8dcSSimon Schubert    the terms of the GNU General Public License as published by the Free
95796c8dcSSimon Schubert    Software Foundation; either version 3, or (at your option) any later
105796c8dcSSimon Schubert    version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
135796c8dcSSimon Schubert    WARRANTY; without even the implied warranty of MERCHANTABILITY or
145796c8dcSSimon Schubert    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
155796c8dcSSimon Schubert    for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert Under Section 7 of GPL version 3, you are granted additional
185796c8dcSSimon Schubert permissions described in the GCC Runtime Library Exception, version
195796c8dcSSimon Schubert 3.1, as published by the Free Software Foundation.
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert You should have received a copy of the GNU General Public License and
225796c8dcSSimon Schubert a copy of the GCC Runtime Library Exception along with this program;
235796c8dcSSimon Schubert see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
245796c8dcSSimon Schubert <http://www.gnu.org/licenses/>.  */
255796c8dcSSimon Schubert 
265796c8dcSSimon Schubert /* ------------------------------------------------------------------ */
275796c8dcSSimon Schubert /* Decimal 128-bit format module header 			      */
285796c8dcSSimon Schubert /* ------------------------------------------------------------------ */
295796c8dcSSimon Schubert 
305796c8dcSSimon Schubert #if !defined(DECIMAL128)
315796c8dcSSimon Schubert   #define DECIMAL128
325796c8dcSSimon Schubert   #define DEC128NAME	 "decimal128"		      /* Short name   */
335796c8dcSSimon Schubert   #define DEC128FULLNAME "Decimal 128-bit Number"     /* Verbose name */
345796c8dcSSimon Schubert   #define DEC128AUTHOR	 "Mike Cowlishaw"	      /* Who to blame */
355796c8dcSSimon Schubert 
365796c8dcSSimon Schubert   /* parameters for decimal128s */
375796c8dcSSimon Schubert   #define DECIMAL128_Bytes  16		/* length		      */
385796c8dcSSimon Schubert   #define DECIMAL128_Pmax   34		/* maximum precision (digits) */
395796c8dcSSimon Schubert   #define DECIMAL128_Emax   6144	/* maximum adjusted exponent  */
405796c8dcSSimon Schubert   #define DECIMAL128_Emin  -6143	/* minimum adjusted exponent  */
415796c8dcSSimon Schubert   #define DECIMAL128_Bias   6176	/* bias for the exponent      */
425796c8dcSSimon Schubert   #define DECIMAL128_String 43		/* maximum string length, +1  */
435796c8dcSSimon Schubert   #define DECIMAL128_EconL  12		/* exp. continuation length   */
445796c8dcSSimon Schubert   /* highest biased exponent (Elimit-1) 			      */
455796c8dcSSimon Schubert   #define DECIMAL128_Ehigh  (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1)
465796c8dcSSimon Schubert 
475796c8dcSSimon Schubert   /* check enough digits, if pre-defined			      */
485796c8dcSSimon Schubert   #if defined(DECNUMDIGITS)
495796c8dcSSimon Schubert     #if (DECNUMDIGITS<DECIMAL128_Pmax)
505796c8dcSSimon Schubert       #error decimal128.h needs pre-defined DECNUMDIGITS>=34 for safe use
515796c8dcSSimon Schubert     #endif
525796c8dcSSimon Schubert   #endif
535796c8dcSSimon Schubert 
545796c8dcSSimon Schubert   #ifndef DECNUMDIGITS
555796c8dcSSimon Schubert     #define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined*/
565796c8dcSSimon Schubert   #endif
575796c8dcSSimon Schubert   #ifndef DECNUMBER
585796c8dcSSimon Schubert     #include "decNumber.h"		/* context and number library */
595796c8dcSSimon Schubert   #endif
605796c8dcSSimon Schubert 
615796c8dcSSimon Schubert   /* Decimal 128-bit type, accessible by bytes			      */
625796c8dcSSimon Schubert   typedef struct {
635796c8dcSSimon Schubert     uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/
645796c8dcSSimon Schubert     } decimal128;
655796c8dcSSimon Schubert 
665796c8dcSSimon Schubert   /* special values [top byte excluding sign bit; last two bits are   */
675796c8dcSSimon Schubert   /* don't-care for Infinity on input, last bit don't-care for NaN]   */
685796c8dcSSimon Schubert   #if !defined(DECIMAL_NaN)
695796c8dcSSimon Schubert     #define DECIMAL_NaN     0x7c	/* 0 11111 00 NaN	      */
705796c8dcSSimon Schubert     #define DECIMAL_sNaN    0x7e	/* 0 11111 10 sNaN	      */
715796c8dcSSimon Schubert     #define DECIMAL_Inf     0x78	/* 0 11110 00 Infinity	      */
725796c8dcSSimon Schubert   #endif
735796c8dcSSimon Schubert 
745796c8dcSSimon Schubert #include "decimal128Local.h"
755796c8dcSSimon Schubert 
765796c8dcSSimon Schubert   /* ---------------------------------------------------------------- */
775796c8dcSSimon Schubert   /* Routines							      */
785796c8dcSSimon Schubert   /* ---------------------------------------------------------------- */
795796c8dcSSimon Schubert 
805796c8dcSSimon Schubert #include "decimal128Symbols.h"
815796c8dcSSimon Schubert 
825796c8dcSSimon Schubert   #ifdef __cplusplus
835796c8dcSSimon Schubert   extern "C" {
845796c8dcSSimon Schubert   #endif
855796c8dcSSimon Schubert 
865796c8dcSSimon Schubert   /* String conversions 					      */
875796c8dcSSimon Schubert   decimal128 * decimal128FromString(decimal128 *, const char *, decContext *);
885796c8dcSSimon Schubert   char * decimal128ToString(const decimal128 *, char *);
895796c8dcSSimon Schubert   char * decimal128ToEngString(const decimal128 *, char *);
905796c8dcSSimon Schubert 
915796c8dcSSimon Schubert   /* decNumber conversions					      */
925796c8dcSSimon Schubert   decimal128 * decimal128FromNumber(decimal128 *, const decNumber *,
935796c8dcSSimon Schubert 				    decContext *);
945796c8dcSSimon Schubert   decNumber * decimal128ToNumber(const decimal128 *, decNumber *);
955796c8dcSSimon Schubert 
965796c8dcSSimon Schubert   /* Format-dependent utilities 				      */
975796c8dcSSimon Schubert   uint32_t    decimal128IsCanonical(const decimal128 *);
985796c8dcSSimon Schubert   decimal128 * decimal128Canonical(decimal128 *, const decimal128 *);
995796c8dcSSimon Schubert 
1005796c8dcSSimon Schubert   #ifdef __cplusplus
1015796c8dcSSimon Schubert   }
1025796c8dcSSimon Schubert   #endif
1035796c8dcSSimon Schubert 
1045796c8dcSSimon Schubert #endif
105