Debian Codegraph @

rpython/translator/c/src/float.h

raw symbols SCIP
1
2 /************************************************************/
3 /*** C header subsection: operations between floats ***/
4
5
6 /*** unary operations ***/
7
8 #define OP_FLOAT_IS_TRUE(x,r) OP_FLOAT_NE(x,0.0,r)
9 #define OP_FLOAT_NEG(x,r) r = -x
10 #define OP_FLOAT_ABS(x,r) r = fabs(x)
11
12 /*** binary operations ***/
13
14 #define OP_FLOAT_EQ(x,y,r) r = (x == y)
15 #define OP_FLOAT_NE(x,y,r) r = (x != y)
16 #define OP_FLOAT_LE(x,y,r) r = (x <= y)
17 #define OP_FLOAT_GT(x,y,r) r = (x > y)
18 #define OP_FLOAT_LT(x,y,r) r = (x < y)
19 #define OP_FLOAT_GE(x,y,r) r = (x >= y)
20
21 #define OP_FLOAT_CMP(x,y,r) \
22 r = ((x > y) - (x < y))
23
24 /* addition, subtraction */
25
26 #define OP_FLOAT_ADD(x,y,r) r = x + y
27 #define OP_FLOAT_SUB(x,y,r) r = x - y
28 #define OP_FLOAT_MUL(x,y,r) r = x * y
29 #define OP_FLOAT_TRUEDIV(x,y,r) r = x / y
30
31 /*** conversions ***/
32
33 #define OP_CAST_FLOAT_TO_INT(x,r) r = (Signed)(x)
34 #define OP_CAST_FLOAT_TO_UINT(x,r) r = (Unsigned)(x)
35 #define OP_CAST_INT_TO_FLOAT(x,r) r = (double)(x)
36 #define OP_CAST_UINT_TO_FLOAT(x,r) r = (double)(x)
37 #define OP_CAST_LONGLONG_TO_FLOAT(x,r) r = rpy_cast_longlong_to_float(x)
38 #define OP_CAST_ULONGLONG_TO_FLOAT(x,r) r = rpy_cast_ulonglong_to_float(x)
39 #define OP_CAST_BOOL_TO_FLOAT(x,r) r = (double)(x)
40
41 #ifdef _WIN32
42 /* The purpose of these two functions is to work around a MSVC bug.
43 The expression '(double)131146795334735160LL' will lead to bogus
44 rounding, but apparently everything is fine if we write instead
45 rpy_cast_longlong_to_float(131146795334735160LL). Tested with
46 MSVC 2008. Note that even if the two functions contain just
47 'return (double)x;' it seems to work on MSVC 2008, but I don't
48 trust that there are no other corner cases.
49 http://stackoverflow.com/questions/33829101/incorrect-double-to-long-conversion
50 */
51 static _inline double rpy_cast_longlong_to_float(long long x)
52 {
53 unsigned int lo = (unsigned int)x;
54 double result = lo;
55 result += ((int)(x >> 32)) * 4294967296.0;
56 return result;
57 }
58 static _inline double rpy_cast_ulonglong_to_float(unsigned long long x)
59 {
60 unsigned int lo = (unsigned int)x;
61 double result = lo;
62 result += ((unsigned int)(x >> 32)) * 4294967296.0;
63 return result;
64 }
65 #else
66 # define rpy_cast_longlong_to_float(x) ((double)(x))
67 # define rpy_cast_ulonglong_to_float(x) ((double)(x))
68 #endif
69
70 #ifdef HAVE_LONG_LONG
71 #define OP_CAST_FLOAT_TO_LONGLONG(x,r) r = (long long)(x)
72 #define OP_CAST_FLOAT_TO_ULONGLONG(x,r) r = (unsigned long long)(x)
73 #define OP_CONVERT_FLOAT_BYTES_TO_LONGLONG(x,r) { double _f = x; memcpy(&r, &_f, sizeof(double)); }
74 #define OP_CONVERT_LONGLONG_BYTES_TO_FLOAT(x,r) { long long _f = x; memcpy(&r, &_f, sizeof(long long)); }
75 #endif
76