예제 #1
0
 public static void ValidateSingle(float value)
 {
     if (!JsonHelpers.IsFinite(value))
     {
         ThrowHelper.ThrowArgumentException_ValueNotSupported();
     }
 }
예제 #2
0
        internal double GetDoubleWithQuotes()
        {
            ReadOnlySpan <byte> span = GetUnescapedSpan();

            if (JsonReaderHelper.TryGetFloatingPointConstant(span, out double value))
            {
                return(value);
            }

            // NETCOREAPP implementation of the TryParse method above permits case-insensitive variants of the
            // float constants "NaN", "Infinity", "-Infinity". This differs from the NETFRAMEWORK implementation.
            // The following logic reconciles the two implementations to enforce consistent behavior.
            if (!(Utf8Parser.TryParse(span, out value, out int bytesConsumed) &&
                  span.Length == bytesConsumed &&
                  JsonHelpers.IsFinite(value)))
            {
                ThrowHelper.ThrowFormatException(NumericType.Double);
            }

            return(value);
        }