]> git.ipfire.org Git - thirdparty/gcc.git/blame - libdecnumber/decimal32.h
* decNumber.c (decStrEq): Cast operands to int before calling
[thirdparty/gcc.git] / libdecnumber / decimal32.h
CommitLineData
e3f15eef 1/* Decimal 32-bit format module header for the decNumber C Library
2 Copyright (C) 2005 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 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
84d7eab9 19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
e3f15eef 21
22#if !defined(DECIMAL32)
23#define DECIMAL32
24#define DEC32NAME "decimal32" /* Short name */
25#define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */
26#define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */
27
28 /* parameters for decimal32s */
29#define DECIMAL32_Bytes 4 /* length */
30#define DECIMAL32_Pmax 7 /* maximum precision (digits) */
31#define DECIMAL32_Emax 96 /* maximum adjusted exponent */
32#define DECIMAL32_Emin -95 /* minimum adjusted exponent */
33#define DECIMAL32_Bias 101 /* bias for the exponent */
34#define DECIMAL32_String 15 /* maximum string length, +1 */
35 /* highest biased exponent (Elimit-1) */
36#define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1)
37
38#ifndef DECNUMDIGITS
39#define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined */
40#endif
41#ifndef DECNUMBER
42#include "decNumber.h" /* context and number library */
43#endif
44
45 /* Decimal 32-bit type, accessible by bytes */
46typedef struct
47{
48 uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits */
49} decimal32;
50
51 /* special values [top byte excluding sign bit; last two bits are
52 don't-care for Infinity on input, last bit don't-care for NaN] */
53#if !defined(DECIMAL_NaN)
54#define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
55#define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
56#define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
57#endif
58
59 /* Macros for accessing decimal32 fields. These assume the argument
60 is a reference (pointer) to the decimal32 structure */
61 /* Get sign */
62#define decimal32Sign(d) ((unsigned)(d)->bytes[0]>>7)
63
64 /* Get combination field */
65#define decimal32Comb(d) (((d)->bytes[0] & 0x7c)>>2)
66
67 /* Get exponent continuation [does not remove bias] */
68#define decimal32ExpCon(d) ((((d)->bytes[0] & 0x03)<<4) \
69 | ((unsigned)(d)->bytes[1]>>4))
70
71 /* Set sign [this assumes sign previously 0] */
72#define decimal32SetSign(d, b) { \
73 (d)->bytes[0]|=((unsigned)(b)<<7);}
74
75 /* Set exponent continuation [does not apply bias] */
76 /* This assumes range has been checked and exponent previously 0; */
77 /* type of exponent must be unsigned */
78#define decimal32SetExpCon(d, e) { \
79 (d)->bytes[0]|=(uint8_t)((e)>>4); \
80 (d)->bytes[1]|=(uint8_t)(((e)&0x0F)<<4);}
81
82 /* ------------------------------------------------------------------ */
83 /* Routines */
84 /* ------------------------------------------------------------------ */
85
86#ifdef IN_LIBGCC2
87#define decimal32FromString __decimal32FromString
88#define decimal32ToString __decimal32ToString
89#define decimal32ToEngString __decimal32ToEngString
90#define decimal32FromNumber __decimal32FromNumber
91#define decimal32ToNumber __decimal32ToNumber
92#endif
93
94/* String conversions. */
95decimal32 *decimal32FromString (decimal32 *, char *, decContext *);
96char *decimal32ToString (decimal32 *, char *);
97char *decimal32ToEngString (decimal32 *, char *);
98
99/* decNumber conversions. */
100decimal32 *decimal32FromNumber (decimal32 *, decNumber *, decContext *);
101decNumber *decimal32ToNumber (decimal32 *, decNumber *);
102
103#endif