We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

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 HELP?

JGoode
Expert
I want to get rid of an error for this bit of code;

if (right_rail = left_rail) then
A = right_rail+0.2
endif

Is there any way I can make the error go away?

Thanks!

(edit): If it can't be made to go away, will my script still be fine?
ArchiCAD 23

Windows 10
6 REPLIES 6
Script is fine.

it is information for You that in some cases when comparing real values, you can get problems like calculation takes longer time or something bigger.

If You wish to get rid of this error avoid something like this:

"if real_value1=real_value2 then...."

Declare a precision range parameter:

EPS=.0001

than instead of comparing values put something like that:

if abs(real_value1-real_value2)<=EPS then....

Best Regards,
Piotr
Ralph Wessel
Mentor
JGoode wrote:
I want to get rid of an error for this bit of code;
if (right_rail = left_rail) then
A = right_rail+0.2
endif
It's warning you that this code might do puzzling and unexpected things. Precision is critical when you are dealing with real numbers. Consider what happens if your variables have the following values:
right_rail = 0.03001
left_rail = 0.02999

If you look at those values in a field or output as text, both will display as 0.03m (or 30.0mm). ARCHICAD will only display to the nearest 10th of a millimetre, so any digits beyond that threshold are rounded. But when a script like this runs:
if (right_rail = left_rail
…the result is false, because the values are different.

Rather than comparing them exactly, check that the difference between them is negligable, i.e. below a level of precision that makes a difference. That's what Piotr's example shows, assuming your level of precision is 0.1mm
Ralph Wessel BArch
Software Engineer Speckle Systems
JGoode
Expert
Ralph wrote:
JGoode wrote:
I want to get rid of an error for this bit of code;
if (right_rail = left_rail) then
A = right_rail+0.2
endif
It's warning you that this code might do puzzling and unexpected things. Precision is critical when you are dealing with real numbers. Consider what happens if your variables have the following values:
right_rail = 0.03001
left_rail = 0.02999

If you look at those values in a field or output as text, both will display as 0.03m (or 30.0mm). ARCHICAD will only display to the nearest 10th of a millimetre, so any digits beyond that threshold are rounded. But when a script like this runs:
if (right_rail = left_rail
…the result is false, because the values are different.

Rather than comparing them exactly, check that the difference between them is negligable, i.e. below a level of precision that makes a difference. That's what Piotr's example shows, assuming your level of precision is 0.1mm
I also have the code;

if (left_rail > right_rail) then
A = left_rail+0.2
endif

if (right_rail > left_rail) then
A = right_rail+0.2
endif

So if one is 0.03001 and the other is 0.2999 then it doesn't matter to me.
ArchiCAD 23

Windows 10
Ralph Wessel
Mentor
JGoode wrote:
I also have the code;
if (left_rail > right_rail) then
A = left_rail+0.2
endif

if (right_rail > left_rail) then
A = right_rail+0.2
endif
Are you looking for something like:
A = max(left_rail, right_rail) + 0.2
Ralph Wessel BArch
Software Engineer Speckle Systems
JGoode
Expert
Ralph wrote:
JGoode wrote:
I also have the code;
if (left_rail > right_rail) then
A = left_rail+0.2
endif

if (right_rail > left_rail) then
A = right_rail+0.2
endif
Are you looking for something like:
A = max(left_rail, right_rail) + 0.2
I seem to have got it not showing the error now with the following;

if (left_rail > right_rail) then
A = left_rail+0.2
endif

if (right_rail > left_rail) then
A = right_rail+0.2
endif

if NOT(right_rail > left_rail) and NOT (left_rail > right_rail) then
A = right_rail+0.2
endif

It might be inefficient code but it's working correctly for me
Care to expand on what :
A = max(left_rail, right_rail) + 0.2
will do? I haven't seen anything similar to this thus far.
ArchiCAD 23

Windows 10
Ralph Wessel
Mentor
JGoode wrote:
Care to expand on what :
A = max(left_rail, right_rail) + 0.2
will do? I haven't seen anything similar to this thus far.
max is a GDL instruction – short for maximum. If you give it a list of numbers, it returns the highest value from that list. You appear to want A to be offset by 200mm from the the higher of left_rail and right_rail, which is just the sort of thing max is designed for. I recommend looking up these functions in the GDL manual just so you know what programming tools are available.
Ralph Wessel BArch
Software Engineer Speckle Systems