1*e4b17023SJohn Marino /* Decimal 128-bit format module header for the decNumber C Library. 2*e4b17023SJohn Marino Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc. 3*e4b17023SJohn Marino Contributed by IBM Corporation. Author Mike Cowlishaw. 4*e4b17023SJohn Marino 5*e4b17023SJohn Marino This file is part of GCC. 6*e4b17023SJohn Marino 7*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 8*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 9*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 10*e4b17023SJohn Marino version. 11*e4b17023SJohn Marino 12*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 14*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15*e4b17023SJohn Marino for more details. 16*e4b17023SJohn Marino 17*e4b17023SJohn Marino Under Section 7 of GPL version 3, you are granted additional 18*e4b17023SJohn Marino permissions described in the GCC Runtime Library Exception, version 19*e4b17023SJohn Marino 3.1, as published by the Free Software Foundation. 20*e4b17023SJohn Marino 21*e4b17023SJohn Marino You should have received a copy of the GNU General Public License and 22*e4b17023SJohn Marino a copy of the GCC Runtime Library Exception along with this program; 23*e4b17023SJohn Marino see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 25*e4b17023SJohn Marino 26*e4b17023SJohn Marino /* ------------------------------------------------------------------ */ 27*e4b17023SJohn Marino /* Decimal 128-bit format module header */ 28*e4b17023SJohn Marino /* ------------------------------------------------------------------ */ 29*e4b17023SJohn Marino 30*e4b17023SJohn Marino #if !defined(DECIMAL128) 31*e4b17023SJohn Marino #define DECIMAL128 32*e4b17023SJohn Marino #define DEC128NAME "decimal128" /* Short name */ 33*e4b17023SJohn Marino #define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */ 34*e4b17023SJohn Marino #define DEC128AUTHOR "Mike Cowlishaw" /* Who to blame */ 35*e4b17023SJohn Marino 36*e4b17023SJohn Marino /* parameters for decimal128s */ 37*e4b17023SJohn Marino #define DECIMAL128_Bytes 16 /* length */ 38*e4b17023SJohn Marino #define DECIMAL128_Pmax 34 /* maximum precision (digits) */ 39*e4b17023SJohn Marino #define DECIMAL128_Emax 6144 /* maximum adjusted exponent */ 40*e4b17023SJohn Marino #define DECIMAL128_Emin -6143 /* minimum adjusted exponent */ 41*e4b17023SJohn Marino #define DECIMAL128_Bias 6176 /* bias for the exponent */ 42*e4b17023SJohn Marino #define DECIMAL128_String 43 /* maximum string length, +1 */ 43*e4b17023SJohn Marino #define DECIMAL128_EconL 12 /* exp. continuation length */ 44*e4b17023SJohn Marino /* highest biased exponent (Elimit-1) */ 45*e4b17023SJohn Marino #define DECIMAL128_Ehigh (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1) 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino /* check enough digits, if pre-defined */ 48*e4b17023SJohn Marino #if defined(DECNUMDIGITS) 49*e4b17023SJohn Marino #if (DECNUMDIGITS<DECIMAL128_Pmax) 50*e4b17023SJohn Marino #error decimal128.h needs pre-defined DECNUMDIGITS>=34 for safe use 51*e4b17023SJohn Marino #endif 52*e4b17023SJohn Marino #endif 53*e4b17023SJohn Marino 54*e4b17023SJohn Marino #ifndef DECNUMDIGITS 55*e4b17023SJohn Marino #define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined*/ 56*e4b17023SJohn Marino #endif 57*e4b17023SJohn Marino #ifndef DECNUMBER 58*e4b17023SJohn Marino #include "decNumber.h" /* context and number library */ 59*e4b17023SJohn Marino #endif 60*e4b17023SJohn Marino 61*e4b17023SJohn Marino /* Decimal 128-bit type, accessible by bytes */ 62*e4b17023SJohn Marino typedef struct { 63*e4b17023SJohn Marino uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/ 64*e4b17023SJohn Marino } decimal128; 65*e4b17023SJohn Marino 66*e4b17023SJohn Marino /* special values [top byte excluding sign bit; last two bits are */ 67*e4b17023SJohn Marino /* don't-care for Infinity on input, last bit don't-care for NaN] */ 68*e4b17023SJohn Marino #if !defined(DECIMAL_NaN) 69*e4b17023SJohn Marino #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ 70*e4b17023SJohn Marino #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ 71*e4b17023SJohn Marino #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ 72*e4b17023SJohn Marino #endif 73*e4b17023SJohn Marino 74*e4b17023SJohn Marino #include "decimal128Local.h" 75*e4b17023SJohn Marino 76*e4b17023SJohn Marino /* ---------------------------------------------------------------- */ 77*e4b17023SJohn Marino /* Routines */ 78*e4b17023SJohn Marino /* ---------------------------------------------------------------- */ 79*e4b17023SJohn Marino 80*e4b17023SJohn Marino #include "decimal128Symbols.h" 81*e4b17023SJohn Marino 82*e4b17023SJohn Marino #ifdef __cplusplus 83*e4b17023SJohn Marino extern "C" { 84*e4b17023SJohn Marino #endif 85*e4b17023SJohn Marino 86*e4b17023SJohn Marino /* String conversions */ 87*e4b17023SJohn Marino decimal128 * decimal128FromString(decimal128 *, const char *, decContext *); 88*e4b17023SJohn Marino char * decimal128ToString(const decimal128 *, char *); 89*e4b17023SJohn Marino char * decimal128ToEngString(const decimal128 *, char *); 90*e4b17023SJohn Marino 91*e4b17023SJohn Marino /* decNumber conversions */ 92*e4b17023SJohn Marino decimal128 * decimal128FromNumber(decimal128 *, const decNumber *, 93*e4b17023SJohn Marino decContext *); 94*e4b17023SJohn Marino decNumber * decimal128ToNumber(const decimal128 *, decNumber *); 95*e4b17023SJohn Marino 96*e4b17023SJohn Marino /* Format-dependent utilities */ 97*e4b17023SJohn Marino uint32_t decimal128IsCanonical(const decimal128 *); 98*e4b17023SJohn Marino decimal128 * decimal128Canonical(decimal128 *, const decimal128 *); 99*e4b17023SJohn Marino 100*e4b17023SJohn Marino #ifdef __cplusplus 101*e4b17023SJohn Marino } 102*e4b17023SJohn Marino #endif 103*e4b17023SJohn Marino 104*e4b17023SJohn Marino #endif 105