internal double GetDoubleWithQuotes()
        {
            ReadOnlySpan <byte> span = GetUnescapedSpan();

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

            char numberFormat = JsonReaderHelper.GetFloatingPointStandardParseFormat(span);

            if (Utf8Parser.TryParse(span, out value, out int bytesConsumed, numberFormat) &&
                span.Length == bytesConsumed)
            {
                // NETCOREAPP implmentation of the TryParse method above permits case-insenstive 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 (!double.IsNaN(value) && !double.IsPositiveInfinity(value) && !double.IsNegativeInfinity(value))
                {
                    return(value);
                }
            }

            throw ThrowHelper.GetFormatException(NumericType.Double);
        }
        internal double GetDoubleFloatingPointConstant()
        {
            ReadOnlySpan <byte> span = GetUnescapedSpan();

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

            throw ThrowHelper.GetFormatException(NumericType.Double);
        }
Beispiel #3
0
        internal float GetSingleFloatingPointConstant()
        {
            ReadOnlySpan <byte> span = GetUnescapedSpan();

            if (!JsonReaderHelper.TryGetFloatingPointConstant(span, out float value))
            {
                ThrowHelper.ThrowFormatException(NumericType.Single);
            }

            return(value);
        }
Beispiel #4
0
        internal float GetSingleWithQuotes()
        {
            ReadOnlySpan <byte> span = GetUnescapedSpan();

            if (JsonReaderHelper.TryGetFloatingPointConstant(span, out float 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.Single);
            }

            return(value);
        }