80 bit floating point arithmetic in C/C++

2019-06-07 03:43发布

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?

3条回答
叼着烟拽天下
2楼-- · 2019-06-07 04:10

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.

查看更多
【Aperson】
3楼-- · 2019-06-07 04:19

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.

查看更多
做自己的国王
4楼-- · 2019-06-07 04:35

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.

查看更多
登录 后发表回答