View Full Version : Calculate always divisible by 2
turbojet
3rd May 2014, 10:25
If there's a function like
crop(0,0,0,-height/6)
that's not always divisible by 2 what is a reliable way to make sure it is?
I came up with crop(0,0,0,-height/6/2*2)
It works this time but is it reliable?
Gavino
3rd May 2014, 11:21
Yes, that's OK.
Note that if height/6 is not a multiple of 2 (eg 77), the result will be rounded down to the nearest multiple (76 in this example).
If instead you want it rounded up (here to 78), you would use instead ((height/6)+1)/2*2
turbojet
3rd May 2014, 12:09
Thanks for the additional info
You can also use bit operations: -bitand(height/6, -2). Place minus inside brackets if you want rounding up.
StainlessS
5th May 2014, 19:10
In Test1() below, I think calculations done by script parser, Test2() calls BitAnd() function
together with function look-up.
Function Test1() {
GSCript("""
h=1023
# S=RT_TimerHP # Not avalable in current RT_Stats
S=RT_Timer
for(i=1,1000000) {
z = -h/6/2*2
}
# return RT_TimerHP-S # Not available in current RT_Stats
return RT_Timer-S
""")
}
Function Test2() {
GSCript("""
h=1023
# S=RT_TimerHP # Not avalable in current RT_Stats
S=RT_Timer
for(i=1,1000000) {
z = -bitand(h/6, -2)
}
# return RT_TimerHP-S # Not available in current RT_Stats
return RT_Timer-S
""")
}
T1=Test1
T2=Test2
#RT_WriteFileF("OUT.txt","Time1 = %f Time2 = %f",T1,T2,append=true) # Not avaialable in current RT_Stats
Blankclip.RT_Subtitle("Time1 = %f Time2 = %f",T1,T2)
Results:
Time1 = 2.041717 Time2 = 507.351349 # 249 plugins in plugins dir
Time1 = 2.038389 Time2 = 121.623680 # Empty Plugins dir
EDITED: Increased interations to 1000,000. Used higher precision timer.
EDIT: Oops, got empty/full plugins timings swapped over, corrected.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.