[Issue 12169] sum(int[]) should return a int
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Feb 15 05:49:57 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12169
Peter Alexander <peter.alexander.au at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |peter.alexander.au at gmail.co
| |m
AssignedTo|nobody at puremagic.com |andrei at erdani.com
--- Comment #1 from Peter Alexander <peter.alexander.au at gmail.com> 2014-02-15 05:49:52 PST ---
This is by design in the code, presumably to avoid overflow (which you are
usually so concerned about, what changed?)
I actually agree with you though. I'd expect sum!(int[]) to return int. In
general, I'd expect sum!(T[]) to return typeof(T.init + T.init), and respect
the language integral promotions.
A nice compromise might be to adjust the API:
int[] xs;
int sum1 = sum(xs);
long sum2 = sum!long(xs);
That way, you can specify what type to return. This also solves the problem of
potential overflows with longs (just specify ReturnType = BigInt).
I'll assign this to Andrei for his thoughts.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list