Page 1 of 1
Mod funtion?
Posted: Wed Feb 04, 2015 7:09 pm
by DrChip
Hi veteran smartbasic coders!
Is there a mod function or a way to add one?
a mod b
a - (b * (a / b))
Eg. 35 mod 3 = 2
Thanks
Re: Mod funtion?
Posted: Wed Feb 04, 2015 7:14 pm
by Mr. Kibernetik
Re: Mod funtion?
Posted: Wed Feb 04, 2015 7:16 pm
by DrChip
Thanks!
Re: Mod funtion?
Posted: Thu Feb 05, 2015 8:09 am
by Henko
Is there a mod function or a way to add one?
a mod b
a - (b * (a / b))
Eg. 35 mod 3 = 2
If there weren't a % operator, you would provide for your own function like:
Code: Select all
print mod(35,3)
def mod(a,b)
return a-b*floor(a/b)
end def
And add that function to your own "utility library" wich can be included in your programs using the {} inclusion.
The huge advantage of functions over subroutines is that they use local variables, so there is no danger of unwanted modifications of varibles in the calling program. On the other hand, if you want to adress "outside" variables in a function, you can use the ".<varname>" construct.
I have begged for a function mechanism in Basic! several times when i was active there (as "Oldie"), but Misoft never even reacted.
Re: Mod funtion?
Posted: Sun Feb 08, 2015 1:59 am
by DrChip
Thanks!!