Convert long double to .NET.

I need to convert some C code (which ran on a Linux machine) to .Net and find some long double operations. These are not special operations, but just some multiplications and divisions that end with a lot of decimal places, it seems that the type was used only because of its size.

What would you do to convert the code? I think, just multiply the values ​​and split at the end to find out if this helps, since the code returns short values ​​at the end anyway, plus I don’t know if the source binary really used the whole size, a long double can provide or if it just used a common 64-bit dual under the hood.

If you don't think this is a good idea, do you know of any class or structure that you can use to wrap and model a long double? Creating a shell in C / C ++ and calling it from .Net is "impossible."

+1
source share
3 answers

Most likely, double long C is actually mapped to double, and therefore, without knowing more about calculations, I assume that you would be fine to use double in C #.

In my experience, it is very rare to find a scientific or technical calculation for which a 64-bit double is not enough.

The only way to be 100% sure that double is enough is to study the algorithm, so this advice is based only on instinct and experience.

+2
source

In .net, you have a decimal code that is currently available at the highest level of accuracy. Decimal is mainly used for financial calculations because it is accurate and has a larger range. However, it is not recommended for scientific calculations, since it is slow compared to double.

0
source

You can try System.Decimal (aka decimal in C #) - this is a 96-bit number with base-10 arithmetic (rounding, etc.), which makes it especially suitable for scenarios related to things like currency. It does not map to IEEE, but depending on the compiler, C does not matter long double ; p Please note that it is implemented in software.

0
source

All Articles