float or float FMT decimals glitch
ClaudiuHKS opened this issue · 1 comments
ClaudiuHKS commented
PrintToServer("StringToFloat(4.200000) = %f, 4.200000 = %f", StringToFloat("4.200000"), 4.200000);
=>
/// StringToFloat(4.200000) = 4.199999, 4.200000 = 4.199999
Tried on i7 4790K, Windows 11, SM 1.12.0.7100 & SMM 2.0.0-dev+1278.
Also, if compiling a SM extension which applies *pParam1 = sp_ftoc(4.200000);
, when PrintToServer()
, will print 4.199999
.
asherkin commented
The behaviour here is as expected, 4.2
can't be accurately represented in a IEEE-754 floating point value - the nearest valid value is 4.19999980926513671875
, which when formatted to a precision of 6 (the default when not included in the format specifier), produces the output you're seeing.