Design forum
cancel
Showing results for 
Search instead for 
Did you mean: 

'Use of real types can result in precision problems'

Durval
Beginner
When trying to edit, in AC9, an object created by AC7, I get the message on the title of this post when the 'Check Script' button is pressed. I haven't changed anything in the scripts yet.
The line where the warning points to have IF statements like these:
IF B=0 THEN ....
IF anyparameter<>0 THEN...
Despite the warnings, the object seems to work perfectly.
What 'real types' is AC talking about??
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14
23 REPLIES 23

Karl Ottenstein
Moderator
Hi Durvall,

I answered this here:
http://archicad-talk.graphisoft.com/viewtopic.php?p=24377#24377

AFAIK, this is only a checkscript warning/aid ... and will not affect the running of an otherwise correct script.

Karl
One of the forum moderators   •   AC 25 USA and earlier   •   MacOS 11.6, iMac Pro

Matthew Lohden
Newcomer
I have run into problems like this with real numbers when using calculated values in conditional statements.

I have had code like this fail:
IF angle = 90 THEN...
...and replaced it with the following which worked:
IF angle > 89.99 & angle < 90.01 THEN...
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

Durval
Beginner
Karl wrote:

AFAIK, this is only a checkscript warning/aid ... and will not affect the running of an otherwise correct script.


In the referred script, I have tens of IFs triggering that warning. So, I wouldn't call it an 'aid', because it is very annoying having to click again and again the 'continue' button every time I need to check for actual errors. I must find a way to get reed of the 'aid', to preserve my finger and my mental health...
I found out that replacing 'IF parameter=0 THEN...' by 'IF NOT(parameter) THEN...' removes the warning. But in other cases, I still didn't figure an efficient alternative.
Matthew wrote:

I have had code like this fail:
IF angle = 90 THEN...

...and replaced it with the following which worked:
IF angle > 89.99 & angle < 90.01 THEN...


What if your angle is 89.991? IMHO, this is actually the one that 'can result in precision problems'... Maybe 'IF NOT(angle-90) THEN...' is a better option. I will test it now.
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14

Matthew Lohden
Newcomer
Durval wrote:
Matthew wrote:

I have had code like this fail:
IF angle = 90 THEN...

...and replaced it with the following which worked:
IF angle > 89.99 & angle < 90.01 THEN...


What if your angle is 89.991? IMHO, this is actually the one that 'can result in precision problems'... Maybe 'IF NOT(angle-90) THEN...' is a better option. I will test it now.
If you need tighter precision use 89.9999. I can't believe that a accuracy to 1/10,000 of a degree can possibly matter to you.

The NOT() function may only work with boolean (true/false, checkbox) parameters. I'd be curious to know if it works though.
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

Karl Ottenstein
Moderator
Durval wrote:
In the referred script, I have tens of IFs triggering that warning. So, I wouldn't call it an 'aid', because it is very annoying having to click again and again the 'continue' button every time I need to check for actual errors. I must find a way to get reed of the 'aid', to preserve my finger and my mental health...
I agree. There should be some preference settings for Check Script. Want to post it to the wish list?

Karl
One of the forum moderators   •   AC 25 USA and earlier   •   MacOS 11.6, iMac Pro

Karl Ottenstein
Moderator
Matthew wrote:
IF angle = 90 THEN...
It is perhaps better to use:
epsilon = 0.001 
... 
IF ABS(angle-90) < epsilon THEN 
where you can specify epsilon once in the master script, for example.

Durval's
IF NOT(angle-90) THEN
is no different than saying angle=90, and so would still have potential representational/precision errors and fail (unless the NOT operator does more than zero/non-zero testing and tests for an epsilon factor).

Karl
One of the forum moderators   •   AC 25 USA and earlier   •   MacOS 11.6, iMac Pro

Durval
Beginner
Matthew wrote:
If you need tighter precision use 89.9999. I can't believe that a accuracy to 1/10,000 of a degree can possibly matter to you.

The accuracy should suffice if value of 'angle' is directly typed by user. But if 'angle' stores a results from a formula in the script, even 1/1,000,000 could lead to 'precision problems', couldn't it?
Matthew wrote:
The NOT() function may only work with boolean (true/false, checkbox) parameters. I'd be curious to know if it works though.

Yes, it works, I just tested. 'NOT(x)' results true if x=0, and results false if x is anything but zero (not necessarily 1).
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14

Durval
Beginner
Karl wrote:
Durval's
IF NOT(angle-90) THEN
is no different than saying angle=90,...
...but NOT(angle-90) doesn't trigger the precision warning, while angle=90 does, god knows why....
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14

Karl Ottenstein
Moderator
Durval wrote:
...but NOT(angle-90) doesn't trigger the precision warning, while angle=90 does, god knows why....
It sort of makes sense to not trigger the warning since the result is to be used for simply a zero/non-zero test ... sort of a boolean conversion. Still subject to problems, but I imagine that's their logic.

The point I was trying to make is that the warning could be real, and I wanted to make sure that less experienced GDL programmers didn't use your 'trick' of NOT(expression) to make the message go away, when really they need the 'epsilon' code for the code to work properly.

For example, in you case, if you KNOW that angle is going to 'snap' to 90, 180, 270, and 0, then your code is fine. The value of 90 may not really be 90 exactly (binary rep), but the representation of 90 will always equal the representation of 90. Right?

But, if the angle is computed, then it is very possible that a value of 90.000000001 or 89.9999999999 might result (or whatever) ... in which case your test for 'equality' would fail, even though the numbers are, from a computer math point of view, really equal.

As an addition to the wish for always turning the warning on or off globally, we could ask that GDL include PRAGMAS as in other languages, so that we could write something like:
#PRAGMA noerrorchecking
IF angle=90 THEN ...
#PRAGMA errorchecking
To turn the warning off on code that we know is fine.

Karl
One of the forum moderators   •   AC 25 USA and earlier   •   MacOS 11.6, iMac Pro

HANIEL
Newcomer
Would using MOD(parameter)=90 work?
Bruce Haniel
imac, OS10.8

Matthew Lohden
Newcomer
To clarify my previous comments here...

I have often used conditional tests of angle values for a variety of purposes (for example, to get symbol texts to appear correctly - not upside down, etc.). I find that I can easily exclude conditions that extremely close to 0, 45, 90, etc. (within 1/100th of a degree) since this is never an intentional setting.

I started doing this in version 6 (or 6.5?) when I found that mirroring elements would result in symbol angles of 359.9994 (or there about).

It is often possible to exclude certain angle values as meaningless. For example, I have moulding and trim objects with adjustable hotspots for the miter angles. Since no trim will ever be mitered to an angle over 175° (90° being a square cut), I set it up so that the part automatically snaps to a self return as soon as this angle is exceeded.

Whether you need to be concerned about accuracy to 0.0001° depends, I suppose, on the circumstances, but I can't imagine any such condition myself.
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

Matthew Lohden
Newcomer
HANIEL wrote:
Would using MOD(parameter)=90 work?
I believe you mean INT(value). MOD uses the form x MOD y and returns the remaining (fractional, decimal) value after dividing x by y.

The INT function will not work if the actual value is 89.99°, and a whole degree (from 90.0000 to 90.9999) is a pretty large range.
Matthew Lohden
Consultant, SF CA

MacPro 8core 32GB Radeon 5870
OSX 10.8 Mountain Lion, XP32, Win 7x64

StuartJames
Newcomer
Won't it be great when macro's (as functions) work 'properly' and we can use;

if MyApprox(Angle, 90, AcceptableError)=TRUE then ...

Define Function "MyApprox" (variable, value, limit)
if ABS(value-variable) <= limit then TRUE
else FALSE

Balazs - where are you?

- Stuart
Tosh Satellite 2GHz/1Mb / Nvid GF '460 Go'
XP pro Sp2 / AC9 / PM9 / AL4 / Pir3 / C4D8.5XL
Graphire 2 / Designjet 10ps, 100

www.MadeToMeasureGDL.com !

Durval
Beginner
The "real types" are worse than I thought.
The warning is haunting me in A LOT of IFs that used to work perfectly in AC7.
I did some simple tests. It seems that any condition wich has an "=" or a "<>" sign in an IF-THEN statement makes the warning to come up.
Is it possible that we can not use such a basic code as "IF something = anything" without the annoying message anymore??
Please tell me I'm wrong...
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14

Karl Ottenstein
Moderator
Durval wrote:
The "real types" are worse than I thought.
The warning is haunting me in A LOT of IFs that used to work perfectly in AC7.
I did some simple tests. It seems that any condition wich has an "=" or a "<>" sign in an IF-THEN statement makes the warning to come up.
Is it possible that we can not use such a basic code as "IF something = anything" without the annoying message anymore??
Please tell me I'm wrong...
It should only happen if either of "something" and "anything" is a real (floating point) number. In fact, the warning should also occur for the <= and >= operators .... anything that includes an exact equality (or the exact inequality <>).

As we discussed earlier, this should be a warning that can be turned off: why don't you make it an official wish over at:
http://archicad-talk.graphisoft.com/viewforum.php?f=31
so we can all vote.


Karl
One of the forum moderators   •   AC 25 USA and earlier   •   MacOS 11.6, iMac Pro

Durval
Beginner
Ok, I'll write a wish/poll about this issue.
But before this, let's clarify the wish a bit.
Where is, in ArchiCAD 9, the equivalent to 'Options>Preferences>Imaging & Calculation>Interrupt with error messages' that was present in AC 7 and older?
I understand what we want is not exactly this. We don't want the option to turn off the actual error messages; just the warning messages, i.e., the messages pointing to issues that don't necessarily prevent the scripts from working correctly.
So, there's another wish embeded in this one: the error/warning messages should be divided in two groups: critical and not-critical, or something alike.
Is that correct?
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14

Durval
Beginner
Ok, the wish is now official:
http://archicad-talk.graphisoft.com/viewtopic.php?t=4827
--- www.dtabach.com.br ---
AC 24 BR – MacBook Pro 2,9 GHz Intel Core i7 16GB RAM Mac OS 10.14

Ralph Wessel
Mentor
Durval wrote:
The line where the warning points to have IF statements like these:
IF B=0 THEN ....
IF anyparameter<>0 THEN...
Despite the warnings, the object seems to work perfectly.
What 'real types' is AC talking about??
This warning is really very helpful, but the way AC communicates it is not. 'Real' types means floating point numbers, i.e. numbers with a fraction part like 3.14159...

If you type something like, "IF (x = 0) ..." where x is a real number, it will definitely do something undesirable in the future. Say you have a real parameter called 'x', and its value is displayed as '0'; yet it is quite possible for the expression (x = 0) to return FALSE. Why? Because 'x' is really 0.0001, but ArchiCAD will not display that level of precision. It knows the value is not zero, but displays 0 to the user. Worse still, trying to type '0' into the value still doesn't make it 0 - ArchiCAD doesn't realise that anything has changed and leaves it as 0.0001. This can be very frustrating for users who don't understand these issues.

I never type expressions like "IF (x = 0) ....". I use the technique Karl described - define a level of precision at the beginning of your script and use that throughout, e.g.
eps = 1e-5
IF (ABS(x) < eps) ...
I think a better wish would be for errors/warnings to be displayed in something like the report window rather than displaying them one by one in a modal dialog box. Ideally you would be able to double click on any warning/error in the list and it would take you to the offending line. That way you can disregard warnings if you want to, but the reminder is always there... you never know when it might spare you a lot of grief.
Ralph Wessel BArch

Olivier Dentan
Newcomer
StuartJames wrote:
Won't it be great when macro's (as functions) work 'properly' and we can use;

if MyApprox(Angle, 90, AcceptableError)=TRUE then ...

Define Function "MyApprox" (variable, value, limit)
if ABS(value-variable) <= limit then TRUE
else FALSE

Balazs - where are you?

- Stuart
Stuart, i agree with you.
Let's take this example about text position (old GV's names to make short).

IF (W~ > 90 AND W~ <= 270) THEN ROT2 180 ELSE ROT2 0
Currently, this script works, with some weaks for limt values, and i understand now, why.
Thanks to all the programmers for their explanations.

According to the new rules, i should write, if i understand correctly
eps=0.0001
IF (ABS(W~ -90) > eps AND ABS(W~ -270) <= eps) THEN ROT2 180 ELSE ROT2 0
it does'nt work.

If i write
IF ((W~ -90) > eps AND (W~ -270) <= eps) THEN ROT2 180 ELSE ROT2 0
this statement works perfectly.

DEFINE STYLE "5" Arial, htex, 5, 0
STYLE "5"
TEXT2 0, 0, mytext

May be i need some explanations to understand better, but i have to say that this is not intuitive for non programmers.
I prefer a more understandable solution, as Stuart proposed.

Didn't find the answer? Start a new discussion

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!