Rounding Lengths UP/Down in GDL

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-09 07:08 AM
I would like to know if there is a hidden function in GDL to round up or down a length parameter ?
if not, what is the best way to implement it ?
Thanks in advance

Solved! Go to Solution.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-09 07:45 AM
length MOD module
i.e. 2.9 MOD 0.3
This will give you the remaining part of the module (0.2 in this case).
So to round down .... 2.9-(2.9 MOD 0.3)
And to round up ... 2.9-(2.9 MOD 0.3) + 0.3
Or you could do it the long way using INT and FRA
Divide the length by the module and this will give you a decimal number.
INT of that number is the total number of whole modules.
FRA of that number is fractional part of the remaining module length.
If the FRA is greater than 0 then round up by (INT+1) x module length
To round down is simply INT x module length.
Barry.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-09 07:45 AM
length MOD module
i.e. 2.9 MOD 0.3
This will give you the remaining part of the module (0.2 in this case).
So to round down .... 2.9-(2.9 MOD 0.3)
And to round up ... 2.9-(2.9 MOD 0.3) + 0.3
Or you could do it the long way using INT and FRA
Divide the length by the module and this will give you a decimal number.
INT of that number is the total number of whole modules.
FRA of that number is fractional part of the remaining module length.
If the FRA is greater than 0 then round up by (INT+1) x module length
To round down is simply INT x module length.
Barry.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-09 08:03 AM


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-18 06:19 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-18 06:37 PM
Barry wrote:You may have problems with this. Suppose you want to round up 2.7. It's already rounded, so the correct value should be 2.7, but your code would generate 3.0 as rounded up value.
And to round up ... 2.9-(2.9 MOD 0.3) + 0.3

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-21 01:31 PM
Durval wrote:
Barry wrote:You may have problems with this. Suppose you want to round up 2.7. It's already rounded, so the correct value should be 2.7, but your code would generate 3.0 as rounded up value.
And to round up ... 2.9-(2.9 MOD 0.3) + 0.3
Very true.
Pretty obvious I am not a particularly good coder.
Code first then fix the problems when you don’t get the result you want - that’s the way I tend to work.

Barry.
Versions 6.5 to 27
i7-10700 @ 2.9Ghz, 32GB ram, GeForce RTX 2060 (6GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-22 01:48 PM
I explain:
The problem is that I have a panel with predefined total fixed widths, composed of 2 outer layers and and a frame, and the user have the ability to choose a unified skin thickness from 0mm to 0.5*panel_thickness, with the condition that it must be rounded mm with NO FRACTIONS
So as long the panel thickness forms an even number there will be no problem, ex:
panel 100mm --- forms ---> skin thickness range [0, 50mm]
But if the panel thickness is an odd number:
panel 125 --- forms ---> skin thickness range [0, 62.5mm] !<--- that is what I´m trying to prevent
Let's study your solutions:
CEIL (x)
Returns the smallest integral value that is not smaller than x (always integer). (copy pasted from GDL manual)
panel 125 --- forms ---> skin thickness range [0, ceil(125*0.5)] will get you a range [0, 63]
but 63*2 = 126 mm panel (error - not acceptable)
ROUND_INT (x)
Returns the rounded integer part of x.
in other words, and using the previous example 62.5 mm will be rounded to 63 mm (error - not acceptable)
On the other hand @Barry's solution may have been wrong, but it pointed out where I needed to go, so I modified his solution in a way that it will fulfill my needs, and not prone to errors it the units used in the template is changed by writing this psuedo_code in GDL
values "skin_thickness" , range (0, (0.5*panel_thickness) - (panel_thickness * 0.5 MOD 0.001) )
So thank you all, if it wasn't for you I wouldn't have been able to get this solution


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-04-22 02:52 PM
Moonlight wrote:I'm glad you found a solution!
values "skin_thickness" , range (0, (0.5*panel_thickness) - (panel_thickness * 0.5 MOD 0.001) )