1132718Skan/* Definitions for simple data type for positive real numbers.
2132718Skan   Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3132718Skan
4132718SkanThis file is part of GCC.
5132718Skan
6132718SkanGCC is free software; you can redistribute it and/or modify it under
7132718Skanthe terms of the GNU General Public License as published by the Free
8132718SkanSoftware Foundation; either version 2, or (at your option) any later
9132718Skanversion.
10132718Skan
11132718SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY
12132718SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or
13132718SkanFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14132718Skanfor more details.
15132718Skan
16132718SkanYou should have received a copy of the GNU General Public License
17132718Skanalong with GCC; see the file COPYING.  If not, write to the Free
18169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
19169689Skan02110-1301, USA.  */
20132718Skan
21132718Skan#ifndef GCC_SREAL_H
22132718Skan#define GCC_SREAL_H
23132718Skan
24132718Skan/* SREAL_PART_BITS has to be an even number.  */
25132718Skan#if (HOST_BITS_PER_WIDE_INT / 2) % 2 == 1
26132718Skan#define SREAL_PART_BITS (HOST_BITS_PER_WIDE_INT / 2 - 1)
27132718Skan#else
28132718Skan#define SREAL_PART_BITS (HOST_BITS_PER_WIDE_INT / 2)
29132718Skan#endif
30132718Skan
31132718Skan#define uhwi unsigned HOST_WIDE_INT
32132718Skan#define MAX_HOST_WIDE_INT (((uhwi) 1 << (HOST_BITS_PER_WIDE_INT - 1)) - 1)
33132718Skan
34132718Skan#define SREAL_MIN_SIG ((uhwi) 1 << (SREAL_PART_BITS - 1))
35132718Skan#define SREAL_MAX_SIG (((uhwi) 1 << SREAL_PART_BITS) - 1)
36132718Skan#define SREAL_MAX_EXP (INT_MAX / 4)
37132718Skan
38132718Skan#if SREAL_PART_BITS < 32
39132718Skan#define SREAL_BITS (SREAL_PART_BITS * 2)
40132718Skan#else
41132718Skan#define SREAL_BITS SREAL_PART_BITS
42132718Skan#endif
43132718Skan
44132718Skan/* Structure for holding a simple real number.  */
45132718Skantypedef struct sreal
46132718Skan{
47132718Skan#if SREAL_PART_BITS < 32
48132718Skan  unsigned HOST_WIDE_INT sig_lo;	/* Significant (lower part).  */
49132718Skan  unsigned HOST_WIDE_INT sig_hi;	/* Significant (higher part).  */
50132718Skan#else
51132718Skan  unsigned HOST_WIDE_INT sig;		/* Significant.  */
52132718Skan#endif
53132718Skan  signed int exp;			/* Exponent.  */
54132718Skan} sreal;
55132718Skan
56132718Skanextern void dump_sreal (FILE *, sreal *);
57132718Skanextern sreal *sreal_init (sreal *, unsigned HOST_WIDE_INT, signed int);
58132718Skanextern HOST_WIDE_INT sreal_to_int (sreal *);
59132718Skanextern int sreal_compare (sreal *, sreal *);
60132718Skanextern sreal *sreal_add (sreal *, sreal *, sreal *);
61132718Skanextern sreal *sreal_sub (sreal *, sreal *, sreal *);
62132718Skanextern sreal *sreal_mul (sreal *, sreal *, sreal *);
63132718Skanextern sreal *sreal_div (sreal *, sreal *, sreal *);
64132718Skan
65132718Skan#endif
66