decimal32.h revision 1.5
190075Sobrien/* Decimal 32-bit format module header for the decNumber C Library. 290075Sobrien Copyright (C) 2005-2013 Free Software Foundation, Inc. 390075Sobrien Contributed by IBM Corporation. Author Mike Cowlishaw. 490075Sobrien 590075Sobrien This file is part of GCC. 690075Sobrien 790075Sobrien GCC is free software; you can redistribute it and/or modify it under 890075Sobrien the terms of the GNU General Public License as published by the Free 9169689Skan Software Foundation; either version 3, or (at your option) any later 10169689Skan version. 1190075Sobrien 1290075Sobrien GCC is distributed in the hope that it will be useful, but WITHOUT ANY 1390075Sobrien WARRANTY; without even the implied warranty of MERCHANTABILITY or 1490075Sobrien FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1590075Sobrien for more details. 1690075Sobrien 1790075SobrienUnder Section 7 of GPL version 3, you are granted additional 1890075Sobrienpermissions described in the GCC Runtime Library Exception, version 1990075Sobrien3.1, as published by the Free Software Foundation. 2090075Sobrien 2190075SobrienYou should have received a copy of the GNU General Public License and 2290075Sobriena copy of the GCC Runtime Library Exception along with this program; 2390075Sobriensee the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2490075Sobrien<http://www.gnu.org/licenses/>. */ 2590075Sobrien 2690075Sobrien/* ------------------------------------------------------------------ */ 2790075Sobrien/* Decimal 32-bit format module header */ 2890075Sobrien/* ------------------------------------------------------------------ */ 2990075Sobrien 3090075Sobrien#if !defined(DECIMAL32) 3190075Sobrien #define DECIMAL32 3290075Sobrien #define DEC32NAME "decimal32" /* Short name */ 3390075Sobrien #define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */ 3490075Sobrien #define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */ 3590075Sobrien 36117395Skan /* parameters for decimal32s */ 3790075Sobrien #define DECIMAL32_Bytes 4 /* length */ 3890075Sobrien #define DECIMAL32_Pmax 7 /* maximum precision (digits) */ 39117395Skan #define DECIMAL32_Emax 96 /* maximum adjusted exponent */ 40169689Skan #define DECIMAL32_Emin -95 /* minimum adjusted exponent */ 4190075Sobrien #define DECIMAL32_Bias 101 /* bias for the exponent */ 4290075Sobrien #define DECIMAL32_String 15 /* maximum string length, +1 */ 4390075Sobrien #define DECIMAL32_EconL 6 /* exp. continuation length */ 4490075Sobrien /* highest biased exponent (Elimit-1) */ 4590075Sobrien #define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1) 4690075Sobrien 4790075Sobrien /* check enough digits, if pre-defined */ 4890075Sobrien #if defined(DECNUMDIGITS) 4990075Sobrien #if (DECNUMDIGITS<DECIMAL32_Pmax) 5090075Sobrien #error decimal32.h needs pre-defined DECNUMDIGITS>=7 for safe use 51117395Skan #endif 52117395Skan #endif 53117395Skan 54117395Skan #ifndef DECNUMDIGITS 55117395Skan #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined*/ 56117395Skan #endif 5790075Sobrien #ifndef DECNUMBER 5890075Sobrien #include "decNumber.h" /* context and number library */ 5990075Sobrien #endif 6090075Sobrien 6190075Sobrien /* Decimal 32-bit type, accessible by bytes */ 6290075Sobrien typedef struct { 6390075Sobrien uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits*/ 6490075Sobrien } decimal32; 6590075Sobrien 6690075Sobrien /* special values [top byte excluding sign bit; last two bits are */ 6790075Sobrien /* don't-care for Infinity on input, last bit don't-care for NaN] */ 6890075Sobrien #if !defined(DECIMAL_NaN) 6990075Sobrien #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ 7090075Sobrien #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ 7190075Sobrien #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ 7290075Sobrien #endif 7390075Sobrien 74117395Skan /* ---------------------------------------------------------------- */ 75117395Skan /* Routines */ 76117395Skan /* ---------------------------------------------------------------- */ 77117395Skan 78117395Skan#include "decimal32Symbols.h" 79117395Skan 80117395Skan #ifdef __cplusplus 81117395Skan extern "C" { 82117395Skan #endif 8390075Sobrien 8490075Sobrien /* String conversions */ 8590075Sobrien decimal32 * decimal32FromString(decimal32 *, const char *, decContext *); 8690075Sobrien char * decimal32ToString(const decimal32 *, char *); 8790075Sobrien char * decimal32ToEngString(const decimal32 *, char *); 88117395Skan 89117395Skan /* decNumber conversions */ 90117395Skan decimal32 * decimal32FromNumber(decimal32 *, const decNumber *, 91117395Skan decContext *); 92117395Skan decNumber * decimal32ToNumber(const decimal32 *, decNumber *); 93117395Skan 94117395Skan /* Format-dependent utilities */ 9590075Sobrien uint32_t decimal32IsCanonical(const decimal32 *); 9690075Sobrien decimal32 * decimal32Canonical(decimal32 *, const decimal32 *); 9790075Sobrien 9890075Sobrien #ifdef __cplusplus 9990075Sobrien } 10090075Sobrien #endif 101117395Skan 102117395Skan#endif 103117395Skan