Use of real types can result in precision problems HELP?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2017-06-30 11:28 AM
2017-06-30
11:28 AM
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
Windows 10
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2017-06-30 11:47 AM
2017-06-30
11:47 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2017-06-30 01:09 PM
2017-06-30
01:09 PM
JGoode wrote: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:
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
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
Central Innovation
Central Innovation
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2017-06-30 01:30 PM
2017-06-30
01:30 PM
Ralph wrote:I also have the code;JGoode wrote: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:
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
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
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
Windows 10
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2017-06-30 01:34 PM
2017-06-30
01:34 PM
JGoode wrote:Are you looking for something like:
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
A = max(left_rail, right_rail) + 0.2
Ralph Wessel BArch
Central Innovation
Central Innovation
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2017-06-30 01:37 PM
2017-06-30
01:37 PM
Ralph wrote:I seem to have got it not showing the error now with the following;JGoode wrote:Are you looking for something like:
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
endifA = max(left_rail, right_rail) + 0.2
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.2will do? I haven't seen anything similar to this thus far.
ArchiCAD 23
Windows 10
Windows 10
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2017-06-30 01:47 PM
2017-06-30
01:47 PM
JGoode wrote:
Care to expand on what :A = max(left_rail, right_rail) + 0.2will do? I haven't seen anything similar to this thus far.
Ralph Wessel BArch
Central Innovation
Central Innovation