Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Use of real types can result in precision problems

Anonymous
Not applicable
I have tried to do some GDL editing and have encountered a script problem under the folowing message:
"Use of real types can result in precision problems at line ..."

What does this mean?
I assume "real types" are normal numbers like 0, 1,2, 3, etc.
Can someone explain the origin of this kind of warning message?
16 REPLIES 16
Frank Beister
Moderator
I still wonder what is "integer inner type"
I think they mean: no declaration requiered, declared inside (=inner) the compiler/interpreter as integer by usage.

But thats awful, because you have no control to proof, if your script does anwhere something to discard the integer state of a variable.
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
Oleg
Expert
Peter wrote:
Comments anyone ?
Peter Devlin
Just IMHO.

There are two stuffs: a variable(parameter) and value.
A variable has a name and value. A variable has type and value has
type, but it is not identical. A type of value is an internal type,
type of representation. A variable from point of view GDL on former
can have type of number ( both integer and floating ) and string as we
can not find out it by GDL ( see VARTYPE ).
So, 9 has introduced internal distinction of types of values for
numbers on integer and floating, like number subtype.
( May be for more effective calculations, I do not know. )
I think, that the internal GDL engine uses this type information in
expressions. I guess it keeps the integer type while possible and will
internally convert type to floating in mixed type expressions.
So I think, that we can use comparisons safely:
IF ivar = 12
If we are sure, that "ivar" has integer value.
Frank Beister
Moderator
If we are sure, that "ivar" has integer value.
Yes. If we are shure. So we have to be aware that it does not become floating point.

But mostly we will not program the change intended. We can not proof, if it has happened accidentally.

I book this feature under "nice for the compiler, not realy helpful for me". 😉
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
Frank Beister
Moderator
Even the debugger doesn't show, if its integer or floating point.

BTW. The debugger just displays as many decimals as adjusted in the general settings for dialogs. It would be more helpful to give us the full or individual selectable precision. As one can see in the plan dump posted before AC/GDL works internal with more decimal places than we can see in the dialogs.
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
Oleg
Expert
F. wrote:
[Yes. If we are shure. So we have to be aware that it does not become floating point.

But mostly we will not program the change intended. We can not proof, if it has happened accidentally.
As far as I remember, AC9 shows a warning of it at script checking.
I do not see a good way to avoid mistakes like this.
For example in strong typed languages C/C++ ( a type of each variable is declared ), I can use the similar mixed type comparison too.
It will be valid ( compiler may generate a warning, but it is not language error ).

Unfortunately there are a lot of things in GDL where possible to be mistaken.
For example, all variables are global - it is awful.
Ed_Brown
Graphisoft Alumni
Graphisoft Alumni
Hello everybody,

We will soon be updating the Technical Standards document. I must agree the original text was not too clear. Hopefully the below makes a bit more sense.

++++++++++++++++++
Before ArchiCAD 9 all numeric values were stored internally as floating point values. This meant that integer values were imprecisely stored. From ArchiCAD 9 integers and hence GDL parameter types that are best described with integers are correctly stored internally as integers.

GDL types internally stored as an Integer
Integer
Boolean
Material
Line type
Fillpattern
Pencolor
Intensity (Light)


GDL types internally stored as a Floating-point
Length
Angle
Real
RGB Color component (Light)

GDL variables still don't require type definition, the type is determined during the interpretation from the value to be loaded into the variable. The output of numeric operators now have a type. You should consult the GDL Manual for this information..

The programmer can safely compare integer types with the equality operator. In fact, from ArchiCAD 9 warnings are now issued, if a programmer tries to directly compare floating point values with integer values using the equality operator. For equality-comparisons of floating-point numbers use a small epsilon value meaning the precision of the comparison. For equality-comparisons of a floating-point number and an integer use the round_int function.

Below some sample methods of testing for equivalence between different numeric types are described:
+++++++++++++++++

Hope this is helpful
Ed
Graphisoft Technical Support
Anonymous
Not applicable
Thank you Ed.
That is very helpfull.
Peter Devlin