Skip to content

Module_Statistics_INumberExtension

cyclone_dll edited this page Jul 6, 2026 · 8 revisions

Location: Home / Statistics module / INumberExtension

Statistics module

INumberExtension

Vorcyc.Mathematics.Statistics.INumberExtension provides extension methods for numeric operations, with SIMD optimization, including finding maximum and minimum values in spans.

All methods below are located in class: Vorcyc.Mathematics.Statistics.INumberExtension


📒Contents


Vorcyc.Mathematics.Statistics.INumberExtension class

Methods

1. Max method

Gets the maximum value in a sequence.

  • public static T Max<T>(this Span<T> span) where T : struct, INumber<T>

    • Parameters:
      • span: The Span of values.
    • Returns: The maximum value in the Span.
  • public static T Max<T>(this T[] values) where T : struct, INumber<T>

    • Parameters:
      • values: The array of values.
    • Returns: The maximum value in the array.
  • public static T Max<T>(this T[] values, int start, int length) where T : struct, INumber<T>

    • Parameters:
      • values: The array of values.
      • start: The starting index of the range.
      • length: The length of the range.
    • Returns: The maximum value in the specified range of the array.

2. LocateMax method

Gets the maximum value and its index in a sequence.

  • public static (int index, T value) LocateMax<T>(this Span<T> span) where T : INumber<T>

    • Parameters:
      • span: The Span of values.
    • Returns: A tuple containing the maximum value and its index.
  • public static (int index, T value) LocateMax<T>(this T[] values) where T : INumber<T>

    • Parameters:
      • values: The array of values.
    • Returns: A tuple containing the maximum value and its index.
  • public static (int index, T value) LocateMax<T>(this T[] values, int start, int length) where T : INumber<T>

    • Parameters:
      • values: The array of values.
      • start: The starting index of the range.
      • length: The length of the range.
    • Returns: A tuple containing the maximum value and its index.

3. Min method

Gets the minimum value in a sequence.

  • public static T Min<T>(this Span<T> span) where T : struct, INumber<T>

    • Parameters:
      • span: The Span of values.
    • Returns: The minimum value in the Span.
  • public static T Min<T>(this T[] values) where T : struct, INumber<T>

    • Parameters:
      • values: The array of values.
    • Returns: The minimum value in the array.
  • public static T Min<T>(this T[] values, int start, int length) where T : struct, INumber<T>

    • Parameters:
      • values: The array of values.
      • start: The starting index of the range.
      • length: The length of the range.
    • Returns: The minimum value in the specified range of the array.

4. LocateMin method

Gets the minimum value and its index in a sequence.

  • public static (int index, T value) LocateMin<T>(this Span<T> span) where T : INumber<T>

    • Parameters:
      • span: The Span of values.
    • Returns: A tuple containing the minimum value and its index.
  • public static (int index, T value) LocateMin<T>(this T[] values) where T : INumber<T>

    • Parameters:
      • values: The array of values.
    • Returns: A tuple containing the minimum value and its index.
  • public static (int index, T value) LocateMin<T>(this T[] values, int start, int length) where T : INumber<T>

    • Parameters:
      • values: The array of values.
      • start: The starting index of the range.
      • length: The length of the range.
    • Returns: A tuple containing the minimum value and its index.

Code example

The following example uses several methods from the INumberExtension class, with comments in the sample:

using System;
using Vorcyc.Mathematics.Statistics;

public class INumberExtensionExample
{
    public static void Main()
    {
        // Define a float array
        float[] floatArray = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };

        // Get maximum and minimum in the array
        float maxFloat = floatArray.Max();
        float minFloat = floatArray.Min();
        Console.WriteLine($"Max value in float array: {maxFloat}");
        Console.WriteLine($"Min value in float array: {minFloat}");

        // Get index and value of maximum and minimum in the array
        var (maxFloatIndex, maxFloatValue) = floatArray.LocateMax();
        var (minFloatIndex, minFloatValue) = floatArray.LocateMin();
        Console.WriteLine($"Max value in float array: {maxFloatValue} at index {maxFloatIndex}");
        Console.WriteLine($"Min value in float array: {minFloatValue} at index {minFloatIndex}");

        // Get maximum and minimum in a specified range of the array
        float maxFloatRange = floatArray.Max(1, 3);
        float minFloatRange = floatArray.Min(1, 3);
        Console.WriteLine($"Max value in float array range: {maxFloatRange}");
        Console.WriteLine($"Min value in float array range: {minFloatRange}");

        // Get index and value of maximum and minimum in a specified range of the array
        var (maxFloatRangeIndex, maxFloatRangeValue) = floatArray.LocateMax(1, 3);
        var (minFloatRangeIndex, minFloatRangeValue) = floatArray.LocateMin(1, 3);
        Console.WriteLine($"Max value in float array range: {maxFloatRangeValue} at index {maxFloatRangeIndex}");
        Console.WriteLine($"Min value in float array range: {minFloatRangeValue} at index {minFloatRangeIndex}");

        // Define an integer array
        int[] intArray = { 1, 2, 3, 4, 5 };

        // Get maximum and minimum in the array
        int maxInt = intArray.Max();
        int minInt = intArray.Min();
        Console.WriteLine($"Max value in int array: {maxInt}");
        Console.WriteLine($"Min value in int array: {minInt}");

        // Get index and value of maximum and minimum in the array
        var (maxIntIndex, maxIntValue) = intArray.LocateMax();
        var (minIntIndex, minIntValue) = intArray.LocateMin();
        Console.WriteLine($"Max value in int array: {maxIntValue} at index {maxIntIndex}");
        Console.WriteLine($"Min value in int array: {minIntValue} at index {minIntIndex}");

        // Get maximum and minimum in a specified range of the array
        int maxIntRange = intArray.Max(1, 3);
        int minIntRange = intArray.Min(1, 3);
        Console.WriteLine($"Max value in int array range: {maxIntRange}");
        Console.WriteLine($"Min value in int array range: {minIntRange}");

        // Get index and value of maximum and minimum in a specified range of the array
        var (maxIntRangeIndex, maxIntRangeValue) = intArray.LocateMax(1, 3);
        var (minIntRangeIndex, minIntRangeValue) = intArray.LocateMin(1, 3);
        Console.WriteLine($"Max value in int array range: {maxIntRangeValue} at index {maxIntRangeIndex}");
        Console.WriteLine($"Min value in int array range: {minIntRangeValue} at index {minIntRangeIndex}");
    }
}

Language / 语言: English · 简体中文


Home


首页

Clone this wiki locally