Allow returning something of type void in a function that returns void
[delight/core.git] / d-gcc-real.h
blob1dd7940ad2c7760ce28587fb82d97154e5529917
1 #ifndef GCC_DCMPLR_D_REAL_H
2 #define GCC_DCMPLR_D_REAL_H
4 struct real_value;
5 struct Type;
7 struct real_t {
8 // Including gcc/real.h presents too many problems, so
9 // just statically allocate enough space for
10 // REAL_VALUE_TYPE.
11 typedef enum {
12 Float,
13 Double,
14 LongDouble,
15 NumModes
16 } MyMode;
17 typedef struct {
18 int c;
19 int s;
20 int e;
21 long m[ (16 + sizeof(long))/sizeof(long) + 1 ];
22 } fake_t;
24 fake_t frv;
26 static void init();
27 static real_t parse(const char * str, MyMode mode);
28 static real_t getnan(MyMode mode);
29 static real_t getinfinity();
31 // This constructor prevent the use of the real_t in a union
32 real_t() { }
33 real_t(const real_t & r);
35 const real_value & rv() const { return * (real_value *) & frv; }
36 real_value & rv() { return * (real_value *) & frv; }
37 real_t(const struct real_value & rv);
38 real_t(int v);
39 real_t(d_uns64 v);
40 real_t(d_int64 v);
41 real_t & operator=(const real_t & r);
42 real_t & operator=(int v);
43 real_t operator+ (const real_t & r);
44 real_t operator- (const real_t & r);
45 real_t operator- ();
46 real_t operator* (const real_t & r);
47 real_t operator/ (const real_t & r);
48 real_t operator% (const real_t & r);
49 bool operator< (const real_t & r);
50 bool operator> (const real_t & r);
51 bool operator<= (const real_t & r);
52 bool operator>= (const real_t & r);
53 bool operator== (const real_t & r);
54 bool operator!= (const real_t & r);
55 //operator d_uns64(); // avoid bugs, but maybe allow operator bool()
56 d_uns64 toInt() const;
57 d_uns64 toInt(Type * real_type, Type * int_type) const;
58 real_t convert(MyMode to_mode) const;
59 bool isZero();
60 bool isNegative();
61 bool floatCompare(int op, const real_t & r);
62 bool isIdenticalTo(const real_t & r) const;
63 void format(char * buf, unsigned buf_size) const;
64 void formatHex(char * buf, unsigned buf_size) const;
65 // for debugging:
66 bool isInf();
67 bool isNan();
68 bool isConversionExact(MyMode to_mode) const;
69 void toBytes(unsigned char * buf, unsigned buf_size);
70 void dump();
71 private:
72 // prevent this from being used
73 real_t & operator=(float) { return *this; }
74 real_t & operator=(double) { return *this; }
75 // real_t & operator=(long double v) { return *this; }
78 typedef struct {
79 real_t maxval, minval, epsilonval/*, nanval, infval*/;
80 d_int64 dig, mant_dig;
81 d_int64 max_10_exp, min_10_exp;
82 d_int64 max_exp, min_exp;
83 } real_t_Properties;
85 extern real_t_Properties real_t_properties[real_t::NumModes];
87 #endif