[Solved] Why does floating-point arithmetic not give exact results when adding decimal fractions?

Binary floating point math is like this. In most programming languages, it is based on the IEEE 754 standard. The crux of the problem is that numbers are represented in this format as a whole number times a power of two; rational numbers (such as 0.1, which is 1/10) whose denominator is not a power … Read more

[Solved] Why the result of ‘0.3 * 3’ is 0.89999999999999 in scala language? [duplicate]

Floating point calculation is reasonably complex subject. This has to do with the binary representation of a floating point number, that doesn’t guarantee every possible number (obviously), to have an exact representation, which can lead to errors in operations, and yes, these errors can propagate. Here is a link on the subject, although it isn’t … Read more

[Solved] accuracy of sinl and cosl function in c++

Do not use the value pi = 22 / 7 if you want accuracy. Please use M_PI which is defined in math.h. In MSVC you also need #define _USE_MATH_DEFINES to make the following values available. #define M_E 2.71828182845904523536 // e #define M_LOG2E 1.44269504088896340736 // log2(e) #define M_LOG10E 0.434294481903251827651 // log10(e) #define M_LN2 0.693147180559945309417 // ln(2) … Read more