1169695Skan/* Decimal 128-bit format module header for the decNumber C Library 2169695Skan Copyright (C) 2005 Free Software Foundation, Inc. 3169695Skan Contributed by IBM Corporation. Author Mike Cowlishaw. 4169695Skan 5169695Skan This file is part of GCC. 6169695Skan 7169695Skan GCC is free software; you can redistribute it and/or modify it under 8169695Skan the terms of the GNU General Public License as published by the Free 9169695Skan Software Foundation; either version 2, or (at your option) any later 10169695Skan version. 11169695Skan 12169695Skan In addition to the permissions in the GNU General Public License, 13169695Skan the Free Software Foundation gives you unlimited permission to link 14169695Skan the compiled version of this file into combinations with other 15169695Skan programs, and to distribute those combinations without any 16169695Skan restriction coming from the use of this file. (The General Public 17169695Skan License restrictions do apply in other respects; for example, they 18169695Skan cover modification of the file, and distribution when not linked 19169695Skan into a combine executable.) 20169695Skan 21169695Skan GCC is distributed in the hope that it will be useful, but WITHOUT ANY 22169695Skan WARRANTY; without even the implied warranty of MERCHANTABILITY or 23169695Skan FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24169695Skan for more details. 25169695Skan 26169695Skan You should have received a copy of the GNU General Public License 27169695Skan along with GCC; see the file COPYING. If not, write to the Free 28169695Skan Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 29169695Skan 02110-1301, USA. */ 30169695Skan 31169695Skan#if !defined(DECIMAL128) 32169695Skan#define DECIMAL128 33169695Skan#define DEC128NAME "decimal128" /* Short name */ 34169695Skan#define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */ 35169695Skan#define DEC128AUTHOR "Mike Cowlishaw" /* Who to blame */ 36169695Skan 37169695Skan#if defined(DECIMAL32) 38169695Skan#error decimal128.h must precede decimal32.h for correct DECNUMDIGITS 39169695Skan#else 40169695Skan#if defined(DECIMAL64) 41169695Skan#error decimal128.h must precede decimal64.h for correct DECNUMDIGITS 42169695Skan#endif 43169695Skan#endif 44169695Skan 45169695Skan /* parameters for decimal128s */ 46169695Skan#define DECIMAL128_Bytes 16 /* length */ 47169695Skan#define DECIMAL128_Pmax 34 /* maximum precision (digits) */ 48169695Skan#define DECIMAL128_Emax 6144 /* maximum adjusted exponent */ 49169695Skan#define DECIMAL128_Emin -6143 /* minimum adjusted exponent */ 50169695Skan#define DECIMAL128_Bias 6176 /* bias for the exponent */ 51169695Skan#define DECIMAL128_String 43 /* maximum string length, +1 */ 52169695Skan /* highest biased exponent (Elimit-1) */ 53169695Skan#define DECIMAL128_Ehigh (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1) 54169695Skan 55169695Skan#ifndef DECNUMDIGITS 56169695Skan#define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined */ 57169695Skan#endif 58169695Skan#ifndef DECNUMBER 59169695Skan#include "decNumber.h" /* context and number library */ 60169695Skan#endif 61169695Skan 62169695Skan /* Decimal 128-bit type, accessible by bytes */ 63169695Skantypedef struct 64169695Skan{ 65169695Skan uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits */ 66169695Skan} decimal128; 67169695Skan 68169695Skan /* special values [top byte excluding sign bit; last two bits are 69169695Skan don't-care for Infinity on input, last bit don't-care for NaN] */ 70169695Skan#if !defined(DECIMAL_NaN) 71169695Skan#define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ 72169695Skan#define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ 73169695Skan#define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ 74169695Skan#endif 75169695Skan 76169695Skan /* Macros for accessing decimal128 fields. These assume the argument 77169695Skan is a reference (pointer) to the decimal128 structure */ 78169695Skan /* Get sign */ 79169695Skan#define decimal128Sign(d) ((unsigned)(d)->bytes[0]>>7) 80169695Skan 81169695Skan /* Get combination field */ 82169695Skan#define decimal128Comb(d) (((d)->bytes[0] & 0x7c)>>2) 83169695Skan 84169695Skan /* Get exponent continuation [does not remove bias] */ 85169695Skan#define decimal128ExpCon(d) ((((d)->bytes[0] & 0x03)<<10) \ 86169695Skan | ((unsigned)(d)->bytes[1]<<2) \ 87169695Skan | ((unsigned)(d)->bytes[2]>>6)) 88169695Skan 89169695Skan /* Set sign [this assumes sign previously 0] */ 90169695Skan#define decimal128SetSign(d, b) { \ 91169695Skan (d)->bytes[0]|=((unsigned)(b)<<7);} 92169695Skan 93169695Skan /* Set exponent continuation [does not apply bias] */ 94169695Skan /* This assumes range has been checked and exponent previously 0; */ 95169695Skan /* type of exponent must be unsigned */ 96169695Skan#define decimal128SetExpCon(d, e) { \ 97169695Skan (d)->bytes[0]|=(uint8_t)((e)>>10); \ 98169695Skan (d)->bytes[1] =(uint8_t)(((e)&0x3fc)>>2); \ 99169695Skan (d)->bytes[2]|=(uint8_t)(((e)&0x03)<<6);} 100169695Skan 101169695Skan /* ------------------------------------------------------------------ */ 102169695Skan /* Routines */ 103169695Skan /* ------------------------------------------------------------------ */ 104169695Skan 105169695Skan#ifdef IN_LIBGCC2 106169695Skan#define decimal128FromString __decimal128FromString 107169695Skan#define decimal128ToString __decimal128ToString 108169695Skan#define decimal128ToEngString __decimal128ToEngString 109169695Skan#define decimal128FromNumber __decimal128FromNumber 110169695Skan#define decimal128ToNumber __decimal128ToNumber 111169695Skan#endif 112169695Skan 113169695Skan /* String conversions */ 114169695Skandecimal128 *decimal128FromString (decimal128 *, const char *, decContext *); 115169695Skanchar *decimal128ToString (const decimal128 *, char *); 116169695Skanchar *decimal128ToEngString (const decimal128 *, char *); 117169695Skan 118169695Skan /* decNumber conversions */ 119169695Skandecimal128 *decimal128FromNumber (decimal128 *, const decNumber *, decContext *); 120169695SkandecNumber *decimal128ToNumber (const decimal128 *, decNumber *); 121169695Skan 122169695Skan#endif 123