I am developing a portable class library in C # and I want the bit to convert double
to long
. The easiest solution to this problem is to use the BitConverter.DoubleToInt64Bits
method, but unfortunately this method is not available in a subset of the Portable Library of the .NET class library.
As an alternative, I came up with the following two-pass bit conversion:
var result = BitConverter.ToInt64(BitConverter.GetBytes(x), 0);
My tests show that this expression consistently produces the same result as DoubleToInt64Bits
. However, my benchmarks also show that this alternative formulation is about four times slower than DoubleToInt64Bits
when it is implemented in the full .NET Framework application.
Using only a subset of the Portable Library, is it possible to implement the DoubleToInt64Bits
replacement, which is faster than my wording above?
source share