Thread overview
[Issue 9170] New: CTFE: Allow reinterpret casts float <-> int
Dec 17, 2012
Don
Dec 18, 2012
Walter Bright
[Issue 9170] (D1 only) CTFE: Allow reinterpret casts float <-> int
Apr 19, 2013
Don
December 17, 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@puremagic.com
        ReportedBy: clugdbug@yahoo.com.au


--- Comment #0 from Don <clugdbug@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: -------
December 18, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9170



--- Comment #1 from github-bugzilla@puremagic.com 2012-12-18 10:13:28 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/234fa182b11aaf7e9c87d5b4ad85a1121691e61a Fix issue 9170 CTFE: Allow reinterpret casts float <-> int

Only allows the special case *(cast(U*))&e, where e is an expression
of type T, T.sizeof == U.sizeof, one type is integral
(int, uint, long, ulong) and the other is floating point (float,
double, ifloat, idouble).
Purpose: allow implementation of HalfFloat.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 18, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9170


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2012-12-18 12:40:09 PST ---
https://github.com/D-Programming-Language/dmd/pull/1383 for D2.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9170



--- Comment #3 from github-bugzilla@puremagic.com 2013-04-18 11:23:02 PDT ---
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/41bc0a847e8390a5c8ae61f013a1b8dc7926a863 Fix issue 9170 CTFE: Allow reinterpret casts float <-> int

Only allows the special case *(cast(U*))&e, where e is an expression
of type T, T.sizeof == U.sizeof, one type is integral
(int, uint, long, ulong) and the other is floating point (float,
double, ifloat, idouble).
Purpose: allow implementation of HalfFloat.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9170


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
            Summary|(D1 only) CTFE: Allow       |CTFE: Allow reinterpret
                   |reinterpret casts float <-> |casts float <-> int
                   |int                         |


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