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

!Restored: Negative Numbers in GDL

Anonymous
Not applicable
I'm trying to make variables in GDL, and it's not recognizing negative numbers. For instance, Temp = -0'-2.0000" * -0'-2.0000". I'm also trying to get the difference between 2 negative numbers. For example, the Difference between -1'-0.0000" and -3'-0.0000" should be -2'-0.0000". However, in algebra using Addition, the result would be -4'-0.0000". If I try to subtract 2 negative numbers in GDL, I get an error.

Why does GDL not handle negative numbers?
11 REPLIES 11
TomWaltz
Participant
It handles them fine. I use them all the time.

Could you give us a little more detail, maybe some actual code?
Tom Waltz
Anonymous
Not applicable
To subtract a negative number is the same as adding a positive one. Are you doing something like "-1 - -3"? Two operators in a row is a no no. As you say the difference (distance on the number line) between -1 and -3 is -2 (but that also depends on the direction you are going), but to get that result you have to add 1 to -3 or subtract 3 from 1.

Forgive me if this seems obvious, but I am having trouble understanding the problem. Generally GDL has no trouble with negative numbers. Two exceptions are:

1. When a negative length is applied to a solid element; such as a slab with negative thickness.

2. When used as an argument in a VALUES statement. This is just a quirk which I get around by assigning the negative values to variables and putting those into the values list.

HTH
Anonymous
Not applicable
Matthew wrote:
2. When used as an argument in a VALUES statement. This is just a quirk which I get around by assigning the negative values to variables and putting those into the values list.
I'm not sure if I understand your problem exactly here, but there is situations when you need to use ( ) when you work with negative values.
But because I don't now when your got your problem, I can't test it.
Anonymous
Not applicable
TurboGlider wrote:
Matthew wrote:
2. When used as an argument in a VALUES statement. This is just a quirk which I get around by assigning the negative values to variables and putting those into the values list.
I'm not sure if I understand your problem exactly here, but there is situations when you need to use ( ) when you work with negative values.
But because I don't now when your got your problem, I can't test it.
I haven't explored this fully. After I found the quick fix I moved on. But the situation is this:
VALUES "for_example" -2, -1, 0, 1, 2
Results in an error. Whereas:
n1 = -2
n2 = -1
VALUES "for_example" n1, n2, 0, 1, 2
Works just fine. I believe it is because operations are not supported within the values list and it interprets the minus sign as part of a subtraction.

Are you saying that the same result can be achieved with parentheses?
Like this:
VALUES "for_example" (-2), (-1), 0, 1, 2
Karl Ottenstein
Moderator
Yes, parentheses are the solution.

Karl
One of the forum moderators
AC 28 USA and earlier   •   macOS Sequoia 15.2, MacBook Pro M2 Max 12CPU/30GPU cores, 32GB
Anonymous
Not applicable
Karl wrote:
Yes, parentheses are the solution.

Karl
Thanks Karl. That seems a little cleaner.
Frank Beister
Moderator
Negative numbers as first values in the VALUES command do not work. another workaround is to use: 0-2
I have reported (and documented on selfgdl 😉 ) that a longer time ago to GS. I thought it would have been fixed in 10, but it does not look like.
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
Anonymous
Not applicable
I already gave an example of the problem in my original post, but just to show it again:

Temp = -0'-1.0000" - -0'-3.0000"

When you make a variable called Temp with -1 minus -3, GDL gives an error.
Anonymous
Not applicable
that looks like matthew's description of two operators in a row. Have you tried the suggestion using () around the second number:

-0'-1.0000" - (-0'-3.0000")

Does that work?