bs Numberic Functions

 

NUMERAL FUNCTIONS                

Function

Description

max(value1,value2,value3,...)

max value of the specified variable

min(value1,value2,...)

min value of the specified variable

numadd(value1,value2..)

add values

sub(value1,value2,..)

subtract (-)

percent(actualvalue,relatedvalue)

determines percent value

mul(value1,value2,..)

multiplicate

dif(value1,value2,..)

divide

mod(value1,value2)

 

The Modulus is the remainder of the euclidean division of one number by another. % is called the modulo operation.

For instance, 9 divided by 4 equals 2 but it remains 1. Here, 9 / 4 = 2 and 9 % 4 = 1.

 

modulus1

 

Calculation

 

The modulo operation can be calculated using this equation:

 

a % b = a - floor(a / b) * b

 

floor(a / b) represents the number of times you can divide a by b

floor(a / b) * b is the amount that was successfully shared entirely

The total (a) minus what was shared equals the remainder of the division

Applied to the last example, this gives:

 

5 % 7 = 5 - floor(5 / 7) * 7 = 5

 

Modular Arithmetic

 

That said, your intuition was that it could be -2 and not 5. Actually, in modular arithmetic, -2 = 5 (mod 7) because it exists k in Z such that 7k - 2 = 5.

 

You may not have learned modular arithmetic, but you have probably used angles and know that -90° is the same as 270° because it is modulo 360. It's similar, it wraps! So take a circle, and say that it's perimeter is 7. Then you read where is 5. And if you try with 10, it should be at 3 because 10 % 7 is 3.

 

in beas script you can use the %mod() function

 

Example

 

decimal lc_value1,lc_value2,lc_result

lc_value1=9

lc_value2=4

lc_result=%mod(lc_value1,lc_value2)

messagebox=<lc_result>

// this return "1"

 

decimal lc_value1,lc_value2,lc_result

lc_value1=10

lc_value2=4

lc_result=%mod(lc_value1,lc_value2)

messagebox=<lc_result>
// this return 2

 

round(value1,roundtyp,rounddec)

 

RoundType

Description

-1

without

0

< 0.5 =0,  >= 0.5 = 1

1

> 0     =1, example: 0.001 = 1, 1.1 = 2

2

< 1     =1, example: 0.99   = 0, 1.2 = 1

3

multiple from .. see example

 

round dec

Type 0, 1 and 2: Count of decimal place

Type 3: Multiple-factor

 

Example

decimal lc_value1,lc_value2,lc_result

lc_value1=10.51234

lc_result=%round(lc_value,1,2)

// this return 10.52
// because it's rounding up with 2 decimal places

 

lc_result=%round(lc_value,2,2)

// this return 10.51 - rounding down

 

lc_value1=11.51234

lc_result=%round(lc_value,1,0)

// reutrn 12
 

// Example multiple by

10 pieces fit on one pallet

I have 15 pieces

round to the total quantity that fits on the required pallets

In this case, I need at least 2 pallets.

On it fit 20 pieces

 

dec lc_pcs,lc_bypallet,lc_result

lc_pcs=15

lc_bypallet=10

lc_result=%round(lc_pcs,3,lc_bypallet)