| 1 |
#include "common_header.h" |
| 2 |
#include <src/support.h> |
| 3 |
#include <src/exception.h> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <stdio.h> |
| 9 |
#include <stdlib.h> |
| 10 |
|
| 11 |
|
| 12 |
#define Sign_bit 0x80000000 |
| 13 |
#define NAN_WORD0 0x7ff80000 |
| 14 |
#define NAN_WORD1 0 |
| 15 |
#ifndef PY_UINT32_T |
| 16 |
#define PY_UINT32_T unsigned int |
| 17 |
#endif |
| 18 |
|
| 19 |
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 20 |
#define IEEE_8087 |
| 21 |
#endif |
| 22 |
|
| 23 |
#ifdef IEEE_8087 |
| 24 |
#define word0(x) (x)->L[1] |
| 25 |
#define word1(x) (x)->L[0] |
| 26 |
#else |
| 27 |
#define word0(x) (x)->L[0] |
| 28 |
#define word1(x) (x)->L[1] |
| 29 |
#endif |
| 30 |
#define dval(x) (x)->d |
| 31 |
|
| 32 |
typedef PY_UINT32_T ULong; |
| 33 |
typedef union { double d; ULong L[2]; } U; |
| 34 |
|
| 35 |
RPY_EXTERN |
| 36 |
void RPyAssertFailed(const char* filename, long lineno, |
| 37 |
const char* function, const char *msg) { |
| 38 |
fprintf(stderr, |
| 39 |
"PyPy assertion failed at %s:%ld:\n" |
| 40 |
"in %s: %s\n", |
| 41 |
filename, lineno, function, msg); |
| 42 |
abort(); |
| 43 |
} |
| 44 |
|
| 45 |
RPY_EXTERN |
| 46 |
void RPyAbort(void) { |
| 47 |
fprintf(stderr, "Invalid RPython operation (NULL ptr or bad array index)\n"); |
| 48 |
abort(); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
double |
| 58 |
_PyPy_dg_stdnan(int sign) |
| 59 |
{ |
| 60 |
U rv; |
| 61 |
word0(&rv) = NAN_WORD0; |
| 62 |
word1(&rv) = NAN_WORD1; |
| 63 |
if (sign) |
| 64 |
word0(&rv) |= Sign_bit; |
| 65 |
return dval(&rv); |
| 66 |
} |