Skip to content

[Enhancement] Please can you add a GetMinMax() style function ? #13

Description

@Smurf-IV

Something better than this ?

    public static void GetMinMax(double[] values, out double min, out double max)
    {
        min = double.NaN;
        max = double.NaN;
        int length = values.Length;
        if (length > 0)
        {
            min = values[0];
            max = min;
            for (int i = 1; i < length; i++)
            {
                double value = values[i];
                if (min > value)
                {
                    min = value;
                }
                else if (max < value)
                {
                    max = value;
                }
            }
        }
    }

Activity

jackmott commented on Jul 8, 2019

@jackmott
Owner

You can't get much faster than that without a SIMD implementation. A small thing you can do is don't use length in the for loop, use values.Length, this will ensure bounds check elimination. And you could use a tuple for the return value rather than two out values (won't change performance just may be nicer to use)

If a SIMD version would be useful let me know, I could add that maybe.

Smurf-IV commented on Jul 8, 2019

@Smurf-IV
Author

A SIMD would be useful, and for completeness the above one (With the changes you have recommended) as well

jackmott commented on Jul 8, 2019

@jackmott
Owner

feel free to submit a PR with the above one! the pain is that you have to implement it for every primitive type. So its easy just annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions