1*e4b17023SJohn Marino /* Definitions for simple data type for positive real numbers. 2*e4b17023SJohn Marino Copyright (C) 2002, 2003, 2007 Free Software Foundation, Inc. 3*e4b17023SJohn Marino 4*e4b17023SJohn Marino This file is part of GCC. 5*e4b17023SJohn Marino 6*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 7*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 8*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 9*e4b17023SJohn Marino version. 10*e4b17023SJohn Marino 11*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 13*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14*e4b17023SJohn Marino for more details. 15*e4b17023SJohn Marino 16*e4b17023SJohn Marino You should have received a copy of the GNU General Public License 17*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see 18*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 19*e4b17023SJohn Marino 20*e4b17023SJohn Marino #ifndef GCC_SREAL_H 21*e4b17023SJohn Marino #define GCC_SREAL_H 22*e4b17023SJohn Marino 23*e4b17023SJohn Marino /* SREAL_PART_BITS has to be an even number. */ 24*e4b17023SJohn Marino #if (HOST_BITS_PER_WIDE_INT / 2) % 2 == 1 25*e4b17023SJohn Marino #define SREAL_PART_BITS (HOST_BITS_PER_WIDE_INT / 2 - 1) 26*e4b17023SJohn Marino #else 27*e4b17023SJohn Marino #define SREAL_PART_BITS (HOST_BITS_PER_WIDE_INT / 2) 28*e4b17023SJohn Marino #endif 29*e4b17023SJohn Marino 30*e4b17023SJohn Marino #define uhwi unsigned HOST_WIDE_INT 31*e4b17023SJohn Marino #define MAX_HOST_WIDE_INT (((uhwi) 1 << (HOST_BITS_PER_WIDE_INT - 1)) - 1) 32*e4b17023SJohn Marino 33*e4b17023SJohn Marino #define SREAL_MIN_SIG ((uhwi) 1 << (SREAL_PART_BITS - 1)) 34*e4b17023SJohn Marino #define SREAL_MAX_SIG (((uhwi) 1 << SREAL_PART_BITS) - 1) 35*e4b17023SJohn Marino #define SREAL_MAX_EXP (INT_MAX / 4) 36*e4b17023SJohn Marino 37*e4b17023SJohn Marino #if SREAL_PART_BITS < 32 38*e4b17023SJohn Marino #define SREAL_BITS (SREAL_PART_BITS * 2) 39*e4b17023SJohn Marino #else 40*e4b17023SJohn Marino #define SREAL_BITS SREAL_PART_BITS 41*e4b17023SJohn Marino #endif 42*e4b17023SJohn Marino 43*e4b17023SJohn Marino /* Structure for holding a simple real number. */ 44*e4b17023SJohn Marino typedef struct sreal 45*e4b17023SJohn Marino { 46*e4b17023SJohn Marino #if SREAL_PART_BITS < 32 47*e4b17023SJohn Marino unsigned HOST_WIDE_INT sig_lo; /* Significant (lower part). */ 48*e4b17023SJohn Marino unsigned HOST_WIDE_INT sig_hi; /* Significant (higher part). */ 49*e4b17023SJohn Marino #else 50*e4b17023SJohn Marino unsigned HOST_WIDE_INT sig; /* Significant. */ 51*e4b17023SJohn Marino #endif 52*e4b17023SJohn Marino signed int exp; /* Exponent. */ 53*e4b17023SJohn Marino } sreal; 54*e4b17023SJohn Marino 55*e4b17023SJohn Marino extern void dump_sreal (FILE *, sreal *); 56*e4b17023SJohn Marino extern sreal *sreal_init (sreal *, unsigned HOST_WIDE_INT, signed int); 57*e4b17023SJohn Marino extern HOST_WIDE_INT sreal_to_int (sreal *); 58*e4b17023SJohn Marino extern int sreal_compare (sreal *, sreal *); 59*e4b17023SJohn Marino extern sreal *sreal_add (sreal *, sreal *, sreal *); 60*e4b17023SJohn Marino extern sreal *sreal_sub (sreal *, sreal *, sreal *); 61*e4b17023SJohn Marino extern sreal *sreal_mul (sreal *, sreal *, sreal *); 62*e4b17023SJohn Marino extern sreal *sreal_div (sreal *, sreal *, sreal *); 63*e4b17023SJohn Marino 64*e4b17023SJohn Marino #endif 65