Re: += on associative arrays leads to surprising result

2019-08-27 Thread berni via Digitalmars-d-learn
On Tuesday, 27 August 2019 at 16:45:53 UTC, Samir wrote: I never understood why the intial value of floats, doubles and reals was NaN. That's for detecting uninitialised variables. If the result of a calculation is NaN, it's likely, that you forgot to initialise the variable.

Re: += on associative arrays leads to surprising result

2019-08-27 Thread Samir via Digitalmars-d-learn
On Tuesday, 27 August 2019 at 16:12:07 UTC, berni wrote: What's your oppinion on this? As someone relatively new to programming in general and to D in particular, this behavior does, on the surface, seem inconsistent. Good to see that a bug exists for this, per ag0aep6g. I never

Re: += on associative arrays leads to surprising result

2019-08-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.08.19 18:12, berni wrote: import std.stdio; void main() {     real[int] a;     a[0] += 100;     writeln(a); } results (independed of the used compiler) in [0:100] I was a little bit surprised, because a[0] += 100 should be the same as a[0] = a[0]+100, which leads to a range

+= on associative arrays leads to surprising result

2019-08-27 Thread berni via Digitalmars-d-learn
import std.stdio; void main() { real[int] a; a[0] += 100; writeln(a); } results (independed of the used compiler) in [0:100] I was a little bit surprised, because a[0] += 100 should be the same as a[0] = a[0]+100, which leads to a range violation error. Furthermore, as we