| 1 | |
| 2 | #define coerce(n, f, t) \ |
| 3 | MLTON_CODEGEN_STATIC_INLINE \ |
| 4 | t f##_##n##To##t (f x) { \ |
| 5 | return (t)x; \ |
| 6 | } |
| 7 | #define bothFromWordCoerce(name, from, to) \ |
| 8 | coerce (name, Word##S##from, to) \ |
| 9 | coerce (name, Word##U##from, to) |
| 10 | #define bothToWordCoerce(name, from, to) \ |
| 11 | coerce (name, from, Word##S##to) \ |
| 12 | coerce (name, from, Word##U##to) |
| 13 | |
| 14 | #define allWordCoerce(size) \ |
| 15 | bothToWordCoerce(rnd, Real32, size) \ |
| 16 | bothToWordCoerce(rnd, Real64, size) \ |
| 17 | bothFromWordCoerce(extd, size, Word8) \ |
| 18 | bothFromWordCoerce(extd, size, Word16) \ |
| 19 | bothFromWordCoerce(extd, size, Word32) \ |
| 20 | bothFromWordCoerce(extd, size, Word64) |
| 21 | |
| 22 | allWordCoerce(8) |
| 23 | allWordCoerce(16) |
| 24 | allWordCoerce(32) |
| 25 | allWordCoerce(64) |
| 26 | |
| 27 | #undef allWordCoerce |
| 28 | #undef bothToWordCoerce |
| 29 | #undef bothFromWordCoerce |
| 30 | |
| 31 | coerce(rnd, Real32, Real32) |
| 32 | coerce(rnd, Real32, Real64) |
| 33 | coerce(rnd, Real64, Real32) |
| 34 | coerce(rnd, Real64, Real64) |
| 35 | |
| 36 | #undef coerce |
| 37 | |
| 38 | #define cast(f, t) \ |
| 39 | MLTON_CODEGEN_STATIC_INLINE \ |
| 40 | t f##_castTo##t (f x) { \ |
| 41 | t y; \ |
| 42 | memcpy(&y, &x, sizeof(t)); \ |
| 43 | return y; \ |
| 44 | } |
| 45 | |
| 46 | cast(Real32, Word32) |
| 47 | cast(Word32, Real32) |
| 48 | cast(Real64, Word64) |
| 49 | cast(Word64, Real64) |
| 50 | |
| 51 | #undef cast |