[Issue 9170] New: CTFE: Allow reinterpret casts float <-> int

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 17 02:06:52 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9170

           Summary: CTFE: Allow reinterpret casts float <-> int
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: clugdbug at yahoo.com.au


--- Comment #0 from Don <clugdbug at yahoo.com.au> 2012-12-17 02:06:33 PST ---
Requested by Walter. This is necessary for implementing things such as
half-float, and is also necessary for implementing printing of floats.

As a bare minimum, the following should be supported:

long testdouble(double x)
{
    return *(cast(long*)&x);
}

int testfloat(float x)
{
    return *(cast(int*)&x);
}

static assert(testfloat(1.25) == 0x3FA0_0000);
static assert(testdouble(1.25) == 0x3FF4_0000_0000_0000L);

Likewise, converting int->float and long->double should be supported.

(Supporting 80-bit reals is also ultimately necessary but is problematic since
no integral type is large enough to contain the entire value. This means it
inevitably exposes endianness, and also involves creating a pointer into part
of a floating-point value).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list