Specify a specific double precision literal in c# -


how can specify specific double precision literal or value in c#?

for example, use constant of largest double value less 1 in program. largest double less 1 1.11111111 11111111 11111111 11111111 11111111 11111111 1111 x 2^(-1) in binary. expressing big-endian double in hex 0x3fe f ffff ffff ffff

i can generate following code:

var largestdoublelessthanonebytes = new byte[] {0x3f, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; if (bitconverter.islittleendian) largestdoublelessthanonebytes = largestdoublelessthanonebytes.reverse().toarray(); double largestdoublelessthanone = bitconverter.todouble(largestdoublelessthanonebytes, 0); 

bitconverter can't used in declaration of const, can't used in place of literal value.

using this tool, can come literal 9.99999999999999888977697537484e-1, ends being same double. bitconverter.tostring(bitconverter.getbytes(9.99999999999999888977697537484e-1)) == "ff-ff-ff-ff-ff-ff-ef-3f".

is there other way specific double values c# code find decimal literal closest double representation double want?

this overkill, damn, why not?

unsafe {     var x = 0x3fefffffffffffff;     var d = *(double*)&x;     console.writeline("{0:r}", d); } 

hello, reinterpret_cast<> in c#


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 -