Re: Int to float?

2015-03-06 Thread bearophile via Digitalmars-d-learn
Ola Fosheim Grøstad: D claims to follow C, so using unions for type punning is ultimately implementation defined. I am not sure if D is the same as C regarding this. Bye, bearophile

Re: Int to float?

2015-03-06 Thread Nicolas Sicard via Digitalmars-d-learn
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

Re: Int to float?

2015-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:32:20 UTC, anonymous wrote: That's not really simpler, though. Maybe, but I think the union is a bit nicer because then the compiler is responsible for more of the details. For example, it should work with class objects without the complication of dealing

Re: Int to float?

2015-03-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); The cast(void*) isn't necessary.

Re: Int to float?

2015-03-05 Thread Taylor Hillegeist via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); ahh of course! lol :)

Re: Int to float?

2015-03-05 Thread badlink via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:16:55 UTC, anonymous wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); The cast(void*) isn't necessary. Actually even the cast is unecessary, just use a uniform.

Re: Int to float?

2015-03-05 Thread Benjamin Thaut via Digitalmars-d-learn
Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue);

Re: Int to float?

2015-03-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:21:18 UTC, badlink wrote: On Thursday, 5 March 2015 at 20:16:55 UTC, anonymous wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); The cast(void*) isn't necessary.

Re: Int to float?

2015-03-05 Thread Jesse Phillips via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:06:55 UTC, Taylor Hillegeist wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: Am 05.03.2015 um 21:00 schrieb Taylor Hillegeist: How to I cast a Int to float without changing its binary representation? int someValue = 5; float sameBinary

Re: Int to float?

2015-03-05 Thread via Digitalmars-d-learn
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