It is just for academic purpose.
I noticed that for integral literals we can declare 18446744073709551615 , which is 2^64-1 or ulong.MaxValue . Defining more than this value results in a compile-time error.
And for floating point literals, we can declare them with an integral part up to 999...999 ( 9 repeated 308 times). Declaring an integral part with a large number of digits again leads to a compile-time error. One thing that interests me is that the compiler seems to be able to specify the fractional part of an unlimited number of digits. A virtually unlimited number of digits for the fractional part does not make sense.
Questions:
Is there a constant representing the maximum number of digits internally defined by the C # compiler for the fractional part of a floating point number?
If such a constant exists, why does the C # compiler not compile a compilation error when users specify fractional parts outside their limit?
Minimal working example 1
namespace FloatingPoint { class Program { static void Main(string[] args) { const ulong @ulong = 18446744073709551615; const double @double = 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999; } } }
Minimal working example 2
using System; namespace FloatingPoint { class Program { static void Main(string[] args) { const double x01 = 0.9; const double x02 = 0.99; const double x03 = 0.999; const double x04 = 0.9999; const double x05 = 0.99999; const double x06 = 0.999999; const double x07 = 0.9999999; const double x08 = 0.99999999; const double x09 = 0.999999999; const double x10 = 0.9999999999; const double x11 = 0.99999999999; const double x12 = 0.999999999999; const double x13 = 0.9999999999999; const double x14 = 0.99999999999999; const double x15 = 0.999999999999999; const double x16 = 0.9999999999999999; const double x17 = 0.99999999999999999; const double x18 = 0.999999999999999999; const double x19 = 0.9999999999999999999; const double x20 = 0.99999999999999999999; Console.WriteLine(x01); Console.WriteLine(x02); Console.WriteLine(x03); Console.WriteLine(x04); Console.WriteLine(x05); Console.WriteLine(x06); Console.WriteLine(x07); Console.WriteLine(x08); Console.WriteLine(x09); Console.WriteLine(x10); Console.WriteLine(x11); Console.WriteLine(x12); Console.WriteLine(x13); Console.WriteLine(x14); Console.WriteLine(x15); Console.WriteLine(x16); Console.WriteLine(x17); Console.WriteLine(x18); Console.WriteLine(x19); Console.WriteLine(x20); } } }
IL:
.method private hidebysig static void Main(string[] args) cil managed { .entrypoint
source share