using System; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; namespace ComputeSharp.NetCore.Tests.Extensions { /// /// An helper with methods to process fixed-size buffers /// public static class SpanExtensions { /// /// The maximum threshold to validate two values as being equal /// private const float FloatThreshold = 0.00001f; /// /// Checks whether or not the two input instances have the same content /// /// The first to check /// The second to check [Pure] public static bool ContentEquals(this Span a, Span b) { if (a.Length != b.Length) return false; if (a.Length == 0) return true; var l = a.Length; ref var ra = ref a.GetPinnableReference(); ref var rb = ref b.GetPinnableReference(); for (var i = 0; i < l; i++) if (Math.Abs(Unsafe.Add(ref ra, i) - Unsafe.Add(ref rb, i)) > FloatThreshold) return false; return true; } } }