reinterpret_cast float to uint
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 29 21:58:37 PDT 2015
On Sun, 29 Mar 2015 17:33:02 +0000, Namespace wrote:
> On Sunday, 29 March 2015 at 16:29:40 UTC, ketmar wrote:
>> On Sun, 29 Mar 2015 16:00:05 +0000, matovitch wrote:
>>
>>> On Sunday, 29 March 2015 at 14:50:24 UTC, ketmar wrote:
>>>> On Sun, 29 Mar 2015 13:45:10 +0000, matovitch wrote:
>>>>
>>>> you can also use unions.
>>>
>>> Good idea ! In my case I think it was better to cast, but this could
>>> be helpful another time thanks ! :)
>>
>> unions also looks better than pointers, and they are easier to read, i
>> think. ;-)
>>
>> union FU {
>> float f;
>> uint u;
>> }
>>
>> void main () pure {
>> float t = 42.0; assert((cast(FU)t).u == 0x42280000);
>> }
>
> AFAIK this would be undefined behaviour in C++, right?
i honestly don't remember. C++ itself is UB. ;-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150330/aa1eefaf/attachment.sig>
More information about the Digitalmars-d-learn
mailing list