80 bit floating point arithmetic in C/C++

最后都变了- 提交于 2019-12-08 08:03:48

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/7016431/80-bit-floating-point-arithmetic-in-c-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!