March 06, 2015 Re: Int to float? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ola Fosheim Grøstad | On Friday, 6 March 2015 at 00:57:16 UTC, Ola Fosheim Grøstad wrote: > On Thursday, 5 March 2015 at 23:50:28 UTC, Jesse Phillips wrote: >> I think I read somewhere you don't want to use unions like this, but I think it is more because you generally don't want to reinterpret bits. > > It is non-portable, since some hardware architectures may use different representations (e.g. different byte order on int and float). Then maybe use std.bitmanip? import std.bitmanip; int i = 5; float f = bigEndianToNative!float(nativeToBigEndian(i)); // or float f = littleEndianToNative!float(nativeToLittleEndian(i)); |
Copyright © 1999-2021 by the D Language Foundation