Object items not using slow float format mode

Report problems with documented functionality
smarq8
Posts: 31
Joined: 16 Jan 2016, 00:33

Object items not using slow float format mode

10 Jan 2017, 09:31

Im not sure is it bug or I something missunderstend but according to documentation samples it look like this SetFunction is called as any other function (line by line)

Code: [Select all] [Download] GeSHi © Codebox Plus

Var = 11.333333
SetFormat, float, 6.2
Var -= 1 ; Sets Var to be 10.33 with one leading space because the total width is 6.
SetFormat, float, 0.2
Var += 1 ; Sets Var to be 11.33 with no leading spaces.
SetFormat, float, 06.0
Var += 0 ; Sets Var to be 000011


but in my cases something strange happen if I put this in non execution sections

In this case I use FloatFast, 0.3 and everythink look good

Code: [Select all] [Download] GeSHi © Codebox Plus

#SingleInstance force
SetFormat, FloatFast, 0.3
o := {}
v := (134.969-0)*1000/1434.98
o.x := (134.969-0)*1000/1434.98
o.y := q:= (134.969-0)*1000/1434.98
u := o.x
msgbox,% "object:" A_Tab round(o.x,14) A_Tab o.x "`nvariable:" A_Tab round(v,14) A_Tab v "`nO2Var:" A_Tab round(u,14) A_Tab u "`no.y:=q:=" A_Tab round(o.y,14) A_Tab o.y
return

f4::reload

Image

In this case I use FloatFast, 0.3 and Float, 0.9 inside function (or out of execution section) that is not even called and everything work as Float, 0.3 excluding objects

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Image

In this sace I use onlny slow mode but this time it not affect to object items even if it should (probably)

Code: [Select all] [Download] GeSHi © Codebox Plus

#SingleInstance force
SetFormat, Float, 0.3
o := {}
v := (134.969-0)*1000/1434.98
o.x := (134.969-0)*1000/1434.98
o.y := q:= (134.969-0)*1000/1434.98
u := o.x
msgbox,% "object:" A_Tab round(o.x,14) A_Tab o.x "`nvariable:" A_Tab round(v,14) A_Tab v "`nO2Var:" A_Tab round(u,14) A_Tab u "`no.y:=q:=" A_Tab round(o.y,14) A_Tab o.y
return
f4::reload

Image

my current ahk_v - 1.1.24.04
User avatar
nnnik
Posts: 2186
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: SetFormat do not affect to object items and other troubles.

10 Jan 2017, 11:55

Hi
You are right SetFormat is called like a Command (not a function) and mostly behaves like any other commands except for a few differences:
n 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.
Though it seems that values directly assigned to items of Objects always use the FloatFast mode.
Recommends AHK Studio
lexikos
Posts: 5410
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Object items not using slow float format mode

11 Jan 2017, 03:43

Note the words "stored in a variable" (above), "When storing a number in a variable" and "the ability of variables to cache integers and floating point numbers" (Fast vs. Slow Mode).

There is nothing written about the effects of Fast vs. Slow mode on objects because there are none.

Slow mode exists for backward-compatibility with scripts which were written before number caching was added (in v1.0.48). Objects can use the more efficient method of storage (not converting to strings) without impacting backward-compatibility, because objects were added later.

I would recommend avoiding the use of SetFormat altogether. If you need to format numbers, use Round() or Format(). It may be a little inconvenient, but it will be clear at exactly which point you expect the number to be formatted, and there will be less risk of confusion.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests