www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9170] New: CTFE: Allow reinterpret casts float <-> int

reply d-bugmail puremagic.com writes:
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



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: -------
Dec 17 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9170




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: -------
Dec 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9170


Walter Bright <bugzilla digitalmars.com> changed:

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



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: -------
Dec 18 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9170




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: -------
Apr 18 2013
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Apr 19 2013