SetFormat deprecated, but not using it causes loss of precision?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SunAndSuch
Posts: 46
Joined: 05 Oct 2015, 12:11

SetFormat deprecated, but not using it causes loss of precision?

25 Nov 2018, 13:34

How to avoid loss of precision when performing mathematical operations?
As I understood from the documentation, AutoHotkey has internal precision 'about' 15 digits and if I don't use SetFormat,FloatFast, the precision should be maintained throughout the whole script. If I use SetFormat,FloatFast and store a value into a variable afterwards, it may result in loss of precision (if less, than 15 decimal places used as the parameter). So I have the following script, which yields different results when using the SetFormat, than when not and I'm wondering why.

Code: Select all

SetFormat,FloatFast,0.16
MsgBox,% Format("{:.16f}",rad2deg2(0.123456789012345)) ;7.0735529626444436 with SetFormat, 7.0735530000000004 without
rad2deg2(a)
{	return b:=a*(180/3.1415926535897932384626433832795) ;Decimals above 15 will be ignored, but shouldn't cause a problem?
}
Of course, I could use Format() inside the function, or - in this case - just return a*(180/3.1415926535897932384626433832795), but that's not my point.
I don't quite understand how Format() function can replace SetFormat, since the latter one affects the whole rest of the script (until a new thread is started), while Format() only affects how a certain value is presented.
Windows 10, Ahk v1 x64-bit.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Ask Jeeves [Bot], Google [Bot] and 107 guests