Re: Advent of Code 2023

2023-12-05 Thread Siarhei Siamashka via Digitalmars-d-learn
On Sunday, 3 December 2023 at 18:56:32 UTC, Johannes Miesenhardt wrote: On Sunday, 3 December 2023 at 14:51:37 UTC, Siarhei Siamashka wrote: [...] Thanks, this is super helpful. I have one other question, in the solution you posted and also the one I posted in the discord today. I was

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;

Re: anonymous structs within structs

2023-12-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 4, 2023 11:26:07 AM MST DLearner via Digitalmars-d-learn wrote: > Suppose we need a construct like: > ``` > void main() { > > struct A { >int I1; >int I2; >char X; > } > > struct B { >A Dummy; >int Var1; >int Var2; >

Re: How to hash SHA256 from string?

2023-12-05 Thread Jacob Shtokolov via Digitalmars-d-learn
On Sunday, 3 December 2023 at 13:42:53 UTC, zoujiaqing wrote: Use botan so easy: Well, what about: ```D import std.digest.sha; import std.stdio; void main() { string appKey = "1"; appKey.sha256Of.toHexString.writeln; } ``` Not

Re: anonymous structs within structs

2023-12-05 Thread DLearner via Digitalmars-d-learn
On Tuesday, 5 December 2023 at 00:31:35 UTC, H. S. Teoh wrote: On Mon, Dec 04, 2023 at 11:46:45PM +, DLearner via Digitalmars-d-learn wrote: [...] Basically, B corresponds to the whole record (and only a whole record can be read). But the task only requires Var1 and Var2, the last two