Re: += on associative arrays leads to surprising result
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
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 understood why the intial value of floats, doubles and reals was NaN. Samir
Re: += on associative arrays leads to surprising result
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 violation error. Furthermore, as we work with real, I'd expected the result to be NaN... Is this a bug? I ask, because it would be quite convenient to use it the way it works now. For what it's worth, it's in Bugzilla: https://issues.dlang.org/show_bug.cgi?id=4463