diff options
Diffstat (limited to 'gcc/testsuite/gcc.c-torture/compile/udconvert.c')
-rw-r--r-- | gcc/testsuite/gcc.c-torture/compile/udconvert.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.c-torture/compile/udconvert.c b/gcc/testsuite/gcc.c-torture/compile/udconvert.c new file mode 100644 index 00000000000..31b494fe08a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/udconvert.c @@ -0,0 +1,30 @@ +double +unsigned_to_double1 (u) + unsigned u; +{ + double d; + d = (int) u; /* convert as from a *signed* integer */ + return ((int) u < 0) + ? d + 4294967296.0 + : d; +} + +/* Alternatively */ + +double +unsigned_to_double2 (u) + unsigned u; +{ + double d; + u -= 2147483648; /* complement sign bit */ + d = (int) u; /* convert as from a *signed* integer */ + return d + 2147483648.0; +} + +unsigned +double_to_unsigned (d) + double d; +{ + d += 2147483648.0; + return ((int) d) - 2147483648; +} |