Search code examples
.netclong-double

Converting long double in .NET


I have to convert some C code (that ran in a Linux machine) to .Net, and found some operations with long double. They are not special operations, just some multiplications and divisions that end with a lot of decimals, it seems the type was used just because of its size.

What would you do in order to convert the code? I'm thinking of just multiply the values and divide back at the end to see if it helps since the code is anyway returning short values at the end, plus I don't know if the original binary was indeed using all the size a long double can provide or if it was just using a common 64-bit double under the hood.

If you don't think this is a good idea, do you know of any class or structure that can be used to wrap and simulate a long double? Making a wrapper in C/C++ and call it from .Net is "not possible".


Solution

  • It's most likely that the C long double actually mapped to a double and so without knowing more about the calculations I'd assume you were fine to use double in C#.

    In my experience it's very rare to find a scientific or engineering calculation for which 64 bit double is not sufficient.

    The only way to be 100% certain that double is sufficient would be to study the algorithm so this advice is based on instinct and experience alone.