| 1 | /* Decimal 32-bit format module header for the decNumber C Library. |
| 2 | Copyright (C) 2005, 2007 Free Software Foundation, Inc. |
| 3 | Contributed by IBM Corporation. Author Mike Cowlishaw. |
| 4 | |
| 5 | This file is part of GCC. |
| 6 | |
| 7 | GCC is free software; you can redistribute it and/or modify it under |
| 8 | the terms of the GNU General Public License as published by the Free |
| 9 | Software Foundation; either version 2, or (at your option) any later |
| 10 | version. |
| 11 | |
| 12 | In addition to the permissions in the GNU General Public License, |
| 13 | the Free Software Foundation gives you unlimited permission to link |
| 14 | the compiled version of this file into combinations with other |
| 15 | programs, and to distribute those combinations without any |
| 16 | restriction coming from the use of this file. (The General Public |
| 17 | License restrictions do apply in other respects; for example, they |
| 18 | cover modification of the file, and distribution when not linked |
| 19 | into a combine executable.) |
| 20 | |
| 21 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 22 | WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 24 | for more details. |
| 25 | |
| 26 | You should have received a copy of the GNU General Public License |
| 27 | along with GCC; see the file COPYING. If not, see |
| 28 | <https://www.gnu.org/licenses/>. */ |
| 29 | |
| 30 | /* ------------------------------------------------------------------ */ |
| 31 | /* Decimal 32-bit format module header */ |
| 32 | /* ------------------------------------------------------------------ */ |
| 33 | |
| 34 | #ifndef DECIMAL32_H |
| 35 | #define DECIMAL32_H |
| 36 | |
| 37 | #define DEC32NAME "decimal32" /* Short name */ |
| 38 | #define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */ |
| 39 | #define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */ |
| 40 | |
| 41 | /* parameters for decimal32s */ |
| 42 | #define DECIMAL32_Bytes 4 /* length */ |
| 43 | #define DECIMAL32_Pmax 7 /* maximum precision (digits) */ |
| 44 | #define DECIMAL32_Emax 96 /* maximum adjusted exponent */ |
| 45 | #define DECIMAL32_Emin -95 /* minimum adjusted exponent */ |
| 46 | #define DECIMAL32_Bias 101 /* bias for the exponent */ |
| 47 | #define DECIMAL32_String 15 /* maximum string length, +1 */ |
| 48 | #define DECIMAL32_EconL 6 /* exp. continuation length */ |
| 49 | /* highest biased exponent (Elimit-1) */ |
| 50 | #define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1) |
| 51 | |
| 52 | /* check enough digits, if pre-defined */ |
| 53 | #if defined(DECNUMDIGITS) |
| 54 | #if (DECNUMDIGITS<DECIMAL32_Pmax) |
| 55 | #error decimal32.h needs pre-defined DECNUMDIGITS>=7 for safe use |
| 56 | #endif |
| 57 | #endif |
| 58 | |
| 59 | #ifndef DECNUMDIGITS |
| 60 | #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined*/ |
| 61 | #endif |
| 62 | #include "libdecnumber/decNumber.h" |
| 63 | |
| 64 | /* Decimal 32-bit type, accessible by bytes */ |
| 65 | typedef struct { |
| 66 | uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits*/ |
| 67 | } decimal32; |
| 68 | |
| 69 | /* special values [top byte excluding sign bit; last two bits are */ |
| 70 | /* don't-care for Infinity on input, last bit don't-care for NaN] */ |
| 71 | #if !defined(DECIMAL_NaN) |
| 72 | #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */ |
| 73 | #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */ |
| 74 | #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */ |
| 75 | #endif |
| 76 | |
| 77 | /* ---------------------------------------------------------------- */ |
| 78 | /* Routines */ |
| 79 | /* ---------------------------------------------------------------- */ |
| 80 | |
| 81 | |
| 82 | /* String conversions */ |
| 83 | decimal32 * decimal32FromString(decimal32 *, const char *, decContext *); |
| 84 | char * decimal32ToString(const decimal32 *, char *); |
| 85 | char * decimal32ToEngString(const decimal32 *, char *); |
| 86 | |
| 87 | /* decNumber conversions */ |
| 88 | decimal32 * decimal32FromNumber(decimal32 *, const decNumber *, |
| 89 | decContext *); |
| 90 | decNumber * decimal32ToNumber(const decimal32 *, decNumber *); |
| 91 | |
| 92 | /* Format-dependent utilities */ |
| 93 | uint32_t decimal32IsCanonical(const decimal32 *); |
| 94 | decimal32 * decimal32Canonical(decimal32 *, const decimal32 *); |
| 95 | |
| 96 | #endif |