@@ -460,6 +460,166 @@ public static BigInteger Average(this Span<BigInteger> source)
460460 return ReadOnlySpanExtensions . Average ( source ) ;
461461 }
462462#endif
463+ /*#################################### MIN ##################################*/
464+ #if NET7_0_OR_GREATER
465+
466+ /// <summary>
467+ /// Computes the Min of all the values in <paramref name="source"/>.
468+ /// </summary>
469+ /// <typeparam name="T">The type of elements in <paramref name="source"/>.</typeparam>
470+ /// <param name="source">The <see cref="Span{T}"/> to operate on.</param>
471+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
472+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
473+ public static T Min < T > ( this Span < T > source ) where T : INumber < T >
474+ {
475+ T sum = source . Sum ( ) ;
476+ return sum / T . CreateChecked ( source . Length ) ;
477+ }
478+ #else
479+
480+ #if NET5_0_OR_GREATER
463481
482+ /// <summary>
483+ /// Computes the Average of all the values in <paramref name="source"/>.
484+ /// </summary>
485+ /// <param name="source">The <see cref="Span{Half}"/> to operate on.</param>
486+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
487+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
488+ public static Half Min ( this Span < Half > source )
489+ {
490+ return ReadOnlySpanExtensions . Min ( source ) ;
491+ }
492+ #endif
493+ /// <summary>
494+ /// Computes the Min of all the values in <paramref name="source"/>.
495+ /// </summary>
496+ /// <param name="source">The <see cref="Span{Byte}"/> to operate on.</param>
497+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
498+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
499+ public static byte Min ( this Span < byte > source )
500+ {
501+ return ReadOnlySpanExtensions . Min ( source ) ;
502+ }
503+
504+ /// <summary>
505+ /// Computes the Min of all the values in <paramref name="source"/>.
506+ /// </summary>
507+ /// <param name="source">The <see cref="Span{UInt16}"/> to operate on.</param>
508+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
509+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
510+ public static ushort Min ( this Span < ushort > source )
511+ {
512+ return ReadOnlySpanExtensions . Min ( source ) ;
513+ }
514+
515+ /// <summary>
516+ /// Computes the Min of all the values in <paramref name="source"/>.
517+ /// </summary>
518+ /// <param name="source">The <see cref="Span{uint32}"/> to operate on.</param>
519+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
520+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
521+ public static uint Min ( this Span < uint > source )
522+ {
523+ return ReadOnlySpanExtensions . Min ( source ) ;
524+ }
525+ /// <summary>
526+ /// Computes the Min of all the values in <paramref name="source"/>.
527+ /// </summary>
528+ /// <param name="source">The <see cref="Span{UInt64}"/> to operate on.</param>
529+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
530+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
531+ public static ulong Min ( this Span < ulong > source )
532+ {
533+ return ReadOnlySpanExtensions . Min ( source ) ;
534+ }
535+
536+ /// <summary>
537+ /// Computes the Min of all the values in <paramref name="source"/>.
538+ /// </summary>
539+ /// <param name="source">The <see cref="Span{SByte}"/> to operate on.</param>
540+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
541+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
542+ public static sbyte Min ( this Span < sbyte > source )
543+ {
544+ return ReadOnlySpanExtensions . Min ( source ) ;
545+ }
546+
547+ /// <summary>
548+ /// Computes the Min of all the values in <paramref name="source"/>.
549+ /// </summary>
550+ /// <param name="source">The <see cref="Span{Int16}"/> to operate on.</param>
551+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
552+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
553+ public static short Min ( this Span < short > source )
554+ {
555+ return ReadOnlySpanExtensions . Min ( source ) ;
556+ }
557+
558+ /// <summary>
559+ /// Computes the Min of all the values in <paramref name="source"/>.
560+ /// </summary>
561+ /// <param name="source">The <see cref="Span{Int32}"/> to operate on.</param>
562+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
563+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
564+ public static int Min ( this Span < int > source )
565+ {
566+ return ReadOnlySpanExtensions . Min ( source ) ;
567+ }
568+
569+ /// <summary>
570+ /// Computes the Min of all the values in <paramref name="source"/>.
571+ /// </summary>
572+ /// <param name="source">The <see cref="Span{Int64}"/> to operate on.</param>
573+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
574+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
575+ public static long Min ( this Span < long > source )
576+ {
577+ return ReadOnlySpanExtensions . Min ( source ) ;
578+ }
579+
580+ /// <summary>
581+ /// Computes the Min of all the values in <paramref name="source"/>.
582+ /// </summary>
583+ /// <param name="source">The <see cref="Span{Single}"/> to operate on.</param>
584+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
585+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
586+ public static float Min ( this Span < float > source )
587+ {
588+ return ReadOnlySpanExtensions . Min ( source ) ;
589+ }
590+
591+ /// <summary>
592+ /// Computes the Min of all the values in <paramref name="source"/>.
593+ /// </summary>
594+ /// <param name="source">The <see cref="Span{Double}"/> to operate on.</param>
595+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
596+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
597+ public static double Min ( this Span < double > source )
598+ {
599+ return ReadOnlySpanExtensions . Min ( source ) ;
600+ }
601+
602+ /// <summary>
603+ /// Computes the Min of all the values in <paramref name="source"/>.
604+ /// </summary>
605+ /// <param name="source">The <see cref="Span{Decimal}"/> to operate on.</param>
606+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
607+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
608+ public static decimal Min ( this Span < decimal > source )
609+ {
610+ return ReadOnlySpanExtensions . Min ( source ) ;
611+ }
612+
613+ /// <summary>
614+ /// Computes the Min of all the values in <paramref name="source"/>.
615+ /// </summary>
616+ /// <param name="source">The <see cref="Span{BigInteger}"/> to operate on.</param>
617+ /// <returns>The Min out of all the values in <paramref name="source"/>.</returns>
618+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
619+ public static BigInteger Min ( this Span < BigInteger > source )
620+ {
621+ return ReadOnlySpanExtensions . Min ( source ) ;
622+ }
623+ #endif
464624 }
465625}
0 commit comments