I think the issue was by ths following , The reason is that pow operates on floating-point values, and different implementations can produce values that differ slightly in their low bits. If you need exact integer results, do integer arithmetic. Contrary to one of the comments in response to the question, converting the result of this call to unsigned long long is perfectly safe (for some sensible meaning of “safe”): unsigned long long can hold the value that this call to pow returns, and the resulting value will be the floating-point result with its fraction discarded.
Unexpected results with double casting numeric datatype in SQL Server
Hope that helps OK, first of all, the result in SQL Server 2017 for real_a is not 778881860. It is 778881856, exactly, just as in SQL Server 2008. How this floating-point value is presented by the client is another matter -- Management Studio shows me 7.788819E+08, sqlcmd produces 7.7888186E+8, and apparently SQL Fiddle uses another library altogether (one I would personally have issue with, seeing as how it obscures significant figures!) This value is not arbitrary. REAL is a single-precision floating point type that cannot represent 778881838.81 exactly. The closest representable value is 778881856, hence your result (the next lower representable value is 778881792). Without casting to INT, you can see this value using
should help you out 12.32 is not representable in the formats your C implementation uses for long double or double. The closest representable value to 12.32 in long double may be 12.319999999999999999722444243843710864894092082977294921875. This would partly explain why your program shows 3, 1, 9, 9, 9, and 9—those are the actual decimal digits of the number.