80 bit floating point arithmetic in C/C++
-
20-12-2020 - |
Question
Let assume a, b
are _int64
variables.
Need to calculate sqrt((long double)a)*sqrt((long double)b)
in high precision 80 bit floating point.
Example. (__int64)(sqrt((long double)a)*sqrt((long double)a) + 0.5) != a
in many cases as should be.
Which win32 C/C++ compiler can manage 80 bit floating point arithmetic?
Solution
You probably should not be using floating point to take the square root of an integer, especially long double
which is poorly supported and might have an approximate (not accurate) sqrtl
on some systems. Instead look up integer square root algorithms.
OTHER TIPS
Are you sure that sqrt() is valid for long doubles?
At least in some environments sqrt() is for doubles, sqrtf() for floats and sqrtl() for long doubles.
Embarcadero's C++Builder will handle 80 bit floating point. Use the long double type, or the (imported from Delphi) Extnded type. They are the same.