Re: Why is this not allowed?

2024-10-06 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 5 October 2024 at 17:26:59 UTC, Steven Schveighoffer wrote: It’s the semicolon. As soon as the closing brace, the declaration is over. You would have to invent new syntax. Maybe type tuple syntax will support this: ```d struct EntityDef { (int hp) stats; } EntityDef ed; int x

Re: Genuine copy of an element from an associative array

2024-10-06 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 3 October 2024 at 12:23:27 UTC, Holzofen wrote: ```d uint64 sod_decompose(const uint64 n, const uint64 mod, const ref uint64[] primes, const ref uint64[uint64][uint64] factorials) { auto result = factorials[n]; for (uint64 k = 2; k < n - 1; k++) {

Precision Error?

2024-10-06 Thread WhatMeWorry` via Digitalmars-d-learn
float computeToFitInWindow(uint rows, uint cols) { // code removed ... writeln(hexWidth); return hexWidth; } unittest { assert(computeToFitInWindow(1, 1) == 2.0f, "This assert failed"); assert(computeToFitInWindow(3, 3) == 0.8f, "This

Re: Precision Error?

2024-10-06 Thread Sergey via Digitalmars-d-learn
On Sunday, 6 October 2024 at 21:09:22 UTC, WhatMeWorry` wrote: float computeToFitInWindow(uint rows, uint cols) { // code removed ... writeln(hexWidth); return hexWidth; } unittest { assert(computeToFitInWindow(1, 1) == 2.0f, "This assert fai

Re: Genuine copy of an element from an associative array

2024-10-06 Thread Holzofen via Digitalmars-d-learn
On Sunday, 6 October 2024 at 10:53:28 UTC, Nick Treleaven wrote: On Thursday, 3 October 2024 at 12:23:27 UTC, Holzofen wrote: [...] Could anybody point me to a way how to make a straight copy without meddling with the source array? You can copy an AA using `dup`: https://dlang.org/phobos/ob