SetFormat outside Auto-execute Section

Report problems with documented functionality
Aurelain
Posts: 34
Joined: 02 Sep 2014, 15:37

SetFormat outside Auto-execute Section

29 Dec 2014, 08:29

This sample code shows that the mere presence (not call) of SetFormat outside the Auto-execute Section alters the expected results.

Code: Select all

Gui Add, ActiveX, vwb, Shell.Explorer
wb.Navigate("about:blank")
wb.document.parentWindow.eval("var result;")
result := Sin(1)
wb.document.parentWindow.result := result
wb.document.parentWindow.eval("alert(result+'='+typeof result);") ; <-- 0.841471=string
ExitApp
return ; <-- end of Auto-execute Section

dummy(){
	SetFormat, %foo%, %bar% ; <-- should have no effect. Comment this to see the difference.
}
Expected behavior: the alert in JS should output 0.8414709848078965=number

Actual behavior: the alert in JS outputs 0.841471=string

Workarounds:
  • don't assign result := Sin(1). Instead, directly assign wb.document.parentWindow.result := Sin(1)
  • take out the SetFormat line (although it's not used at all)
Relevant documentation: SetFormat and Auto-execute Section
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SetFormat outside Auto-execute Section

29 Dec 2014, 11:28

In v1.0.48+, floating point variables have about 15 digits of precision internally unless SetFormat Float (i.e. the slow mode) is present anywhere in the script. In that case, the stored precision of floating point numbers is determined by DecimalPlaces (like it was in pre-1.0.48 versions). In other words, once a floating point result is stored in a variable, the extra precision is lost and cannot be reclaimed without redoing the calculation with something like SetFormat, Float, 0.15. To avoid this loss of precision, avoid using SetFormat Float anywhere in the script, or use SetFormat FloatFast instead.
Source
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: SetFormat outside Auto-execute Section

29 Dec 2014, 17:03

The presence of SetFormat %a%,... affects the default behaviour in the same way as SetFormat Float,... for the reason described in the source code, below.

Code: Select all

		if (line.ArgHasDeref(1)) // Something like "SetFormat, %Var%, ..."
		{
			// For the following and other sections further below that disable the cache, can't wait until
			// runtime execution encounters SetFormat to disable caching because script might rely on the
			// *default* format being *immediately* written out prior to the script changing SetFormat at
			// some later time.
			g_WriteCacheDisabledInt64 = TRUE;
			g_WriteCacheDisabledDouble = TRUE;
		}
Another workaround is to avoid SetFormat altogether and use Format() where needed.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 56 guests