View source code
Display the source code in std/numeric.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinglocal clone.
Function std.numeric.normalize
Normalizes values in range by multiplying each element with a
number chosen such that values sum up to sum. If elements in range sum to zero, assigns sum / range to
all. Normalization makes sense only if all elements in range are
positive. normalize assumes that is the case without checking it.
Returns
true if normalization completed normally, false if
all elements in range were zero or if range is empty.
Example
double[] a = [];
assert(!normalize(a));
a = [ 1.0, 3.0 ];
assert(normalize(a));
writeln(a); // [0.25, 0.75]
assert(normalize!(typeof(a))(a, 50)); // a = [12.5, 37.5]
a = [ 0.0, 0.0 ];
assert(!normalize(a));
writeln(a); // [0.5, 0.5]
Authors
Andrei Alexandrescu, Don Clugston, Robert Jacques, Ilya Yaroshenko
License
Copyright © 1999-2025 by the D Language Foundation | Page generated by ddox.