Re: union default initialization values

2023-12-06 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 6 December 2023 at 12:38:35 UTC, Nick Treleaven wrote: Correct. So I expected a NaN output for x. However, I wasn't expecting lo == 13835058055282163712 and hi == 32767 where x is of type real, or lo == 9221120237041090560 and hi = 0 where x is of type double. Based on the

Re: union default initialization values

2023-12-06 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 5 December 2023 at 19:47:38 UTC, confuzzled wrote: On 12/6/23 4:28 AM, Adam D Ruppe wrote: On Tuesday, 5 December 2023 at 19:24:51 UTC, confuzzled wrote: Given the following union union F {     double x;     struct {     ulong lo;     ulong hi;     } } The default value

Re: union default initialization values

2023-12-05 Thread confuzzled via Digitalmars-d-learn
On 12/6/23 4:47 AM, H. S. Teoh wrote: On Wed, Dec 06, 2023 at 04:24:51AM +0900, confuzzled via Digitalmars-d-learn wrote: [...] Also, if you don't understand how floating-point in computers work, I highly recommend reading this:

Re: union default initialization values

2023-12-05 Thread confuzzled via Digitalmars-d-learn
On 12/6/23 4:28 AM, Adam D Ruppe wrote: On Tuesday, 5 December 2023 at 19:24:51 UTC, confuzzled wrote: Given the following union union F {     double x;     struct {     ulong lo;     ulong hi;     } } The default value of this would be `double.init`, since the first member of the

Re: union default initialization values

2023-12-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Dec 06, 2023 at 04:24:51AM +0900, confuzzled via Digitalmars-d-learn wrote: [...] > import std.stdio; > void main() > { > F fp; > fp.lo.writeln; // Why is this not zero? How is this value derived? > fp.hi.writeln; // expected > fp.x.writeln; // expected > > fp.x = >

Re: union default initialization values

2023-12-05 Thread Adam D Ruppe via Digitalmars-d-learn
On Tuesday, 5 December 2023 at 19:24:51 UTC, confuzzled wrote: Given the following union union F { double x; struct { ulong lo; ulong hi; } } The default value of this would be `double.init`, since the first member of the union is a `double`, which is a kind of

union default initialization values

2023-12-05 Thread confuzzled via Digitalmars-d-learn
Given the following union union F { double x; struct { ulong lo; ulong hi; } } I do not understand the output below. Please clarify. import std.stdio; void main() { F fp; fp.lo.writeln; // Why is this not zero? How is this value derived? fp.hi.writeln;