C# compiler does not limit the number of digits of fractional part of a floating-point literal -


this academic purpose.

i noticed integral literals, can declare 18446744073709551615 2^64-1 or ulong.maxvalue. defining greater value produces compile-time error.

and floating-point literals, can declare them integral part 999...999 (9 repeated 308 times). declaring integral part more digits again produces compile-time error. 1 thing interests me compiler seems allow specify fractional part unlimited number of digits. practically, unlimited number of digits fractional part not make sense.

questions:

  1. is there constant representing max number of digits internally defined c# compiler fractional part of floating-point number?

  2. if such constant exists, why not c# compiler throw compile-time error when users specify fractional parts beyond 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);          }     } }  /* output:  0.9 0.99 0.999 0.9999 0.99999 0.999999 0.9999999 0.99999999 0.999999999 0.9999999999 0.99999999999 0.999999999999 0.9999999999999 0.99999999999999 0.999999999999999 1 1 1 1 1 */ 

il:

.method private hidebysig static void  main(string[] args) cil managed {   .entrypoint   // code size       302 (0x12e)   .maxstack  1   il_0000:  nop   il_0001:  ldc.r8     0.90000000000000002   il_000a:  call       void [mscorlib]system.console::writeline(float64)   il_000f:  nop   il_0010:  ldc.r8     0.98999999999999999   il_0019:  call       void [mscorlib]system.console::writeline(float64)   il_001e:  nop   il_001f:  ldc.r8     0.999   il_0028:  call       void [mscorlib]system.console::writeline(float64)   il_002d:  nop   il_002e:  ldc.r8     0.99990000000000001   il_0037:  call       void [mscorlib]system.console::writeline(float64)   il_003c:  nop   il_003d:  ldc.r8     0.99999000000000005   il_0046:  call       void [mscorlib]system.console::writeline(float64)   il_004b:  nop   il_004c:  ldc.r8     0.99999899999999997   il_0055:  call       void [mscorlib]system.console::writeline(float64)   il_005a:  nop   il_005b:  ldc.r8     0.99999990000000005   il_0064:  call       void [mscorlib]system.console::writeline(float64)   il_0069:  nop   il_006a:  ldc.r8     0.99999998999999995   il_0073:  call       void [mscorlib]system.console::writeline(float64)   il_0078:  nop   il_0079:  ldc.r8     0.99999999900000003   il_0082:  call       void [mscorlib]system.console::writeline(float64)   il_0087:  nop   il_0088:  ldc.r8     0.99999999989999999   il_0091:  call       void [mscorlib]system.console::writeline(float64)   il_0096:  nop   il_0097:  ldc.r8     0.99999999999   il_00a0:  call       void [mscorlib]system.console::writeline(float64)   il_00a5:  nop   il_00a6:  ldc.r8     0.99999999999900002   il_00af:  call       void [mscorlib]system.console::writeline(float64)   il_00b4:  nop   il_00b5:  ldc.r8     0.99999999999989997   il_00be:  call       void [mscorlib]system.console::writeline(float64)   il_00c3:  nop   il_00c4:  ldc.r8     0.99999999999999001   il_00cd:  call       void [mscorlib]system.console::writeline(float64)   il_00d2:  nop   il_00d3:  ldc.r8     0.999999999999999   il_00dc:  call       void [mscorlib]system.console::writeline(float64)   il_00e1:  nop   il_00e2:  ldc.r8     0.99999999999999989   il_00eb:  call       void [mscorlib]system.console::writeline(float64)   il_00f0:  nop   il_00f1:  ldc.r8     1.   il_00fa:  call       void [mscorlib]system.console::writeline(float64)   il_00ff:  nop   il_0100:  ldc.r8     1.   il_0109:  call       void [mscorlib]system.console::writeline(float64)   il_010e:  nop   il_010f:  ldc.r8     1.   il_0118:  call       void [mscorlib]system.console::writeline(float64)   il_011d:  nop   il_011e:  ldc.r8     1.   il_0127:  call       void [mscorlib]system.console::writeline(float64)   il_012c:  nop   il_012d:  ret } // end of method program::main 

  1. yes, aren't decimal digits
  2. specification of fractional parts beyond ability represent them easy, when specification decimal , representation binary. 0.3 requires approximation.

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -