I think it depends on how many problems you want. You can convert double to long, so if you converted your double values ββto long integers in a separate program and output constant values, you can use them in your program.
I would strongly discourage this, by the way, but sometimes you have to do what you need.
First write a program to convert your doubles to longs:
Console.WriteLine("private const long x1 = 0x{0:X16}L;", BitConverter.DoubleToInt64Bits(0.5)); Console.WriteLine("private const long x2 = 0x{0:X16}L;", BitConverter.DoubleToInt64Bits(3.14));
Now add this output to your program and create an enumeration:
private const long x1 = 0x3FE0000000000000L; private const long x2 = 0x40091EB851EB851FL; enum MyEnum : long { val1 = x1, val2 = x2 }
If you want to check the double value against an enumeration, you need to call BitConverter.DoubleToInt64Bits() and pass the result to your enumeration type. To convert another method, call BitConverter.Int64BitsToDouble() .
Jim mischel
source share