Thread overview | |||||
---|---|---|---|---|---|
|
January 30, 2016 Computing the min() / max() of a slice of doubles. | ||||
---|---|---|---|---|
| ||||
I want to use std.algorithm.min/max, how would I apply that to a slice of doubles and not a tuple of args? Thanks. |
January 30, 2016 Re: Computing the min() / max() of a slice of doubles. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Enjoys Math | On Saturday, 30 January 2016 at 04:13:09 UTC, Enjoys Math wrote:
> I want to use std.algorithm.min/max,
>
> how would I apply that to a slice of doubles and not a tuple of args?
>
> Thanks.
Combine it with reduce:
import std.algorithm;
void main() {
double[] arr = [1.0, 2.1, 3.2, 4.3, 5.4];
assert(arr.reduce!max == 5.4);
assert(arr.reduce!min == 1.0);
}
|
January 30, 2016 Re: Computing the min() / max() of a slice of doubles. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Enjoys Math | On Saturday, 30 January 2016 at 04:13:09 UTC, Enjoys Math wrote:
> I want to use std.algorithm.min/max,
>
> how would I apply that to a slice of doubles and not a tuple of args?
>
> Thanks.
Oh I got it:
import std.algorithm;
reduce!(max)(slice);
I'ma D wizard!
|
Copyright © 1999-2021 by the D Language Foundation