Skip to content

Double doesn't Parse correctly #10110

@cyberphone

Description

@cyberphone

While doing some mathematical stuff that worked fine in Java I found that C# / .NET does a rather poor job on parsing double values:

Number2Parse=4.3413853813852797e+192 IEEE754=67ee7316b1545878 C#=4.3413853813852797E+192
Number2Parse=4.34138538138528e+192 IEEE754=67ee7316b1545878 C#=4.3413853813852797E+192

You can verify in any browser that 4.3413853813852797e+192 and 4.34138538138528e+192 are distinct values. Version: CLR v4.0.30319

using System;

namespace mathbug
{
    class Program
    {
        static void ShowNumber(string number2Parse)
        {
            double d = Double.Parse(number2Parse);
            ulong ieee754 = (ulong)BitConverter.DoubleToInt64Bits(d);
            Console.WriteLine("Number2Parse=" + number2Parse + " IEEE754=" + Convert.ToString((long)ieee754, 16) + " C#=" + d.ToString("G17"));
        }
 
        static void Main(string[] args)
        {
            ShowNumber("4.3413853813852797e+192");
            ShowNumber("4.34138538138528e+192");
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions