@@ -791,6 +791,237 @@ public static BigInteger Min(this ReadOnlySpan<BigInteger> source)
791791 }
792792 return min ;
793793 }
794+ #endif
795+ /*################################ MAX #######################################*/
796+ #if NET7_0_OR_GREATER
797+
798+ /// <summary>
799+ /// Computes the Max of all the values in <paramref name="source"/>.
800+ /// </summary>
801+ /// <typeparam name="T">The type of elements in the <see cref="ReadOnlySpan{T}"/>.</typeparam>
802+ /// <param name="source">The <see cref="ReadOnlySpan{T}"/> to operate on.</param>
803+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
804+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
805+ public static T Max < T > ( this ReadOnlySpan < T > source ) where T : INumber < T >
806+ {
807+ T Max = source [ 0 ] ;
808+ for ( int x = 1 ; x < source . Length ; x ++ )
809+ {
810+ Max = source [ x ] > Max ? source [ x ] : Max ;
811+ }
812+ return Max ;
813+ }
814+ #else
815+
816+ #if NET5_0_OR_GREATER
817+
818+ /// <summary>
819+ /// Computes the Max of all the values in <paramref name="source"/>.
820+ /// </summary>
821+ /// <param name="source">The <see cref="ReadOnlySpan{Half}"/> to operate on.</param>
822+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
823+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
824+ public static Half Max ( this ReadOnlySpan < Half > source )
825+ {
826+ Half Max = source [ 0 ] ;
827+ for ( int x = 1 ; x < source . Length ; x ++ )
828+ {
829+ Max = source [ x ] > Max ? source [ x ] : Max ;
830+ }
831+ return Max ;
832+ }
833+ #endif
834+ /// <summary>
835+ /// Computes the Max of all the values in <paramref name="source"/>.
836+ /// </summary>
837+ /// <param name="source">The <see cref="ReadOnlySpan{Byte}"/> to operate on.</param>
838+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
839+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
840+ public static byte Max ( this ReadOnlySpan < byte > source )
841+ {
842+ byte Max = source [ 0 ] ;
843+ for ( int x = 1 ; x < source . Length ; x ++ )
844+ {
845+ Max = source [ x ] > Max ? source [ x ] : Max ;
846+ }
847+ return Max ;
848+ }
849+
850+ /// <summary>
851+ /// Computes the Max of all the values in <paramref name="source"/>.
852+ /// </summary>
853+ /// <param name="source">The <see cref="ReadOnlySpan{UInt16}"/> to operate on.</param>
854+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
855+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
856+ public static ushort Max ( this ReadOnlySpan < ushort > source )
857+ {
858+ ushort Max = source [ 0 ] ;
859+ for ( int x = 1 ; x < source . Length ; x ++ )
860+ {
861+ Max = source [ x ] > Max ? source [ x ] : Max ;
862+ }
863+ return Max ;
864+ }
865+
866+ /// <summary>
867+ /// Computes the Max of all the values in <paramref name="source"/>.
868+ /// </summary>
869+ /// <param name="source">The <see cref="ReadOnlySpan{uint32}"/> to operate on.</param>
870+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
871+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
872+ public static uint Max ( this ReadOnlySpan < uint > source )
873+ {
874+ uint Max = source [ 0 ] ;
875+ for ( int x = 1 ; x < source . Length ; x ++ )
876+ {
877+ Max = source [ x ] > Max ? source [ x ] : Max ;
878+ }
879+ return Max ;
880+ }
881+
882+ /// <summary>
883+ /// Computes the Max of all the values in <paramref name="source"/>.
884+ /// </summary>
885+ /// <param name="source">The <see cref="ReadOnlySpan{UInt64}"/> to operate on.</param>
886+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
887+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
888+ public static ulong Max ( this ReadOnlySpan < ulong > source )
889+ {
890+ ulong Max = source [ 0 ] ;
891+ for ( int x = 1 ; x < source . Length ; x ++ )
892+ {
893+ Max = source [ x ] > Max ? source [ x ] : Max ;
894+ }
895+ return Max ;
896+ }
897+
898+ /// <summary>
899+ /// Computes the Max of all the values in <paramref name="source"/>.
900+ /// </summary>
901+ /// <param name="source">The <see cref="ReadOnlySpan{SByte}"/> to operate on.</param>
902+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
903+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
904+ public static sbyte Max ( this ReadOnlySpan < sbyte > source )
905+ {
906+ sbyte Max = source [ 0 ] ;
907+ for ( int x = 1 ; x < source . Length ; x ++ )
908+ {
909+ Max = source [ x ] > Max ? source [ x ] : Max ;
910+ }
911+ return Max ;
912+ }
913+
914+ /// <summary>
915+ /// Computes the Max of all the values in <paramref name="source"/>.
916+ /// </summary>
917+ /// <param name="source">The <see cref="ReadOnlySpan{Int16}"/> to operate on.</param>
918+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
919+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
920+ public static short Max ( this ReadOnlySpan < short > source )
921+ {
922+ short Max = source [ 0 ] ;
923+ for ( int x = 1 ; x < source . Length ; x ++ )
924+ {
925+ Max = source [ x ] > Max ? source [ x ] : Max ;
926+ }
927+ return Max ;
928+ }
929+
930+ /// <summary>
931+ /// Computes the Max of all the values in <paramref name="source"/>.
932+ /// </summary>
933+ /// <param name="source">The <see cref="ReadOnlySpan{Int32}"/> to operate on.</param>
934+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
935+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
936+ public static int Max ( this ReadOnlySpan < int > source )
937+ {
938+ int Max = source [ 0 ] ;
939+ for ( int x = 1 ; x < source . Length ; x ++ )
940+ {
941+ Max = source [ x ] > Max ? source [ x ] : Max ;
942+ }
943+ return Max ;
944+ }
945+
946+ /// <summary>
947+ /// Computes the Max of all the values in <paramref name="source"/>.
948+ /// </summary>
949+ /// <param name="source">The <see cref="ReadOnlySpan{Int64}"/> to operate on.</param>
950+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
951+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
952+ public static long Max ( this ReadOnlySpan < long > source )
953+ {
954+ long Max = source [ 0 ] ;
955+ for ( int x = 1 ; x < source . Length ; x ++ )
956+ {
957+ Max = source [ x ] > Max ? source [ x ] : Max ;
958+ }
959+ return Max ;
960+ }
961+
962+ /// <summary>
963+ /// Computes the Max of all the values in <paramref name="source"/>.
964+ /// </summary>
965+ /// <param name="source">The <see cref="ReadOnlySpan{Single}"/> to operate on.</param>
966+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
967+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
968+ public static float Max ( this ReadOnlySpan < float > source )
969+ {
970+ float Max = source [ 0 ] ;
971+ for ( int x = 1 ; x < source . Length ; x ++ )
972+ {
973+ Max = source [ x ] > Max ? source [ x ] : Max ;
974+ }
975+ return Max ;
976+ }
977+
978+ /// <summary>
979+ /// Computes the Max of all the values in <paramref name="source"/>.
980+ /// </summary>
981+ /// <param name="source">The <see cref="ReadOnlySpan{Double}"/> to operate on.</param>
982+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
983+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
984+ public static double Max ( this ReadOnlySpan < double > source )
985+ {
986+ double Max = source [ 0 ] ;
987+ for ( int x = 1 ; x < source . Length ; x ++ )
988+ {
989+ Max = source [ x ] > Max ? source [ x ] : Max ;
990+ }
991+ return Max ;
992+ }
993+
994+ /// <summary>
995+ /// Computes the Max of all the values in <paramref name="source"/>.
996+ /// </summary>
997+ /// <param name="source">The <see cref="ReadOnlySpan{Int64}"/> to operate on.</param>
998+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
999+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1000+ public static decimal Max ( this ReadOnlySpan < decimal > source )
1001+ {
1002+ decimal Max = source [ 0 ] ;
1003+ for ( int x = 1 ; x < source . Length ; x ++ )
1004+ {
1005+ Max = source [ x ] > Max ? source [ x ] : Max ;
1006+ }
1007+ return Max ;
1008+ }
1009+
1010+ /// <summary>
1011+ /// Computes the Max of all the values in <paramref name="source"/>.
1012+ /// </summary>
1013+ /// <param name="source">The <see cref="ReadOnlySpan{BigInteger}"/> to operate on.</param>
1014+ /// <returns>The Max out of all the values in <paramref name="source"/>.</returns>
1015+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1016+ public static BigInteger Max ( this ReadOnlySpan < BigInteger > source )
1017+ {
1018+ BigInteger Max = source [ 0 ] ;
1019+ for ( int x = 1 ; x < source . Length ; x ++ )
1020+ {
1021+ Max = source [ x ] > Max ? source [ x ] : Max ;
1022+ }
1023+ return Max ;
1024+ }
7941025#endif
7951026 }
7961027}
0 commit comments