[Issue 12610] New: std.algorithm.reduce (with seed) and array-wise operation produces incorrect result
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Apr 21 15:57:51 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12610
Issue ID: 12610
Summary: std.algorithm.reduce (with seed) and array-wise
operation produces incorrect result
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: acehreli at yahoo.com
The following program produces incorrect and random results like [373728176],
[-2022052576], etc.
(Build *without* -inline.)
import std.stdio;
import std.algorithm;
void main()
{
int[] arr = [ 0 ];
int[1] seed;
int[] result = reduce!((sum, _) => sum[])(seed, arr);
writefln("%s", result);
}
Any of the following is sufficient to cover up the issue:
* Building with -inline
* Not slicing sum inside the lambda but returning it directly (i.e. => sum)
* Inserting a writefln expression inside the lambda
Ali
--
More information about the Digitalmars-d-bugs
mailing list