How to serialize a double.

Jerry via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Nov 30 16:45:53 PST 2016


On Thursday, 1 December 2016 at 00:36:30 UTC, Jake Pittis wrote:
> How do I convert a double to a ubyte[]?
>
> I've tried all sorts of things including converting the double 
> to a ulong and trying to serialize the ulong. For example test 
> bellow fails.
>
> ````
> unittest {
>     double d = 3.14;
>     ulong l = *cast(ulong*)(&d);
>     double after = *cast(double*)(&l));
>     assert(after == d); // This fails.
> }
> ````

That test passes for me, are you sure there isn't something else 
wrong with your code? Check to see if it works for just a ulong 
that has values in it's upper 32-bits?


More information about the Digitalmars-d-learn mailing list