Improvement to std.numeric examples in documentation
BoraxMan
rotflol2 at hotmail.com
Sat Dec 28 03:28:33 UTC 2019
For the normalize function in std.numeric, I think an example of
how to use bool normalize(R) where there is a sum value provided
should be included.
The reason for this is that the examples given are as follows,
and none show how the second sum parameter is given.
double[] a = [];
assert(!normalize(a));
a = [ 1.0, 3.0 ];
assert(normalize(a));
writeln(a); // [0.25, 0.75]
a = [ 0.0, 0.0 ];
assert(!normalize(a));
writeln(a); // [0.5, 0.5]
When one tries to do something like "normalize(a,10)", dmd
reports this error.
> Error: template instance normalize!(no, 100) does not match
> template declaration normalize(R)(R range, ElementType!R sum =
> 1)
One must actually specify the template parameter, thus
> assert(normalise!(typeof(a)(a,100));
I guess for those more familiar with the language, this would be
clear, but for those not as familiar just wanting to use a
standard library function, they may be wondering why simply
adding the second 'sum' parameter causes an error, or why IFTI
isn't working. I know I got a little stuck.
I also wonder why this second parameter means that DMD cannot
deduce the type that (R) is.
More information about the Digitalmars-d
mailing list