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
Mod funtion?
- Mr. Kibernetik
- Site Admin
- Posts: 4786
- Joined: Mon Nov 19, 2012 10:16 pm
- My devices: iPhone, iPad, MacBook
- Location: Russia
- Flag:
Re: Mod funtion?
Code: Select all
PRINT 35 % 3
-
- Posts: 167
- Joined: Wed Oct 22, 2014 3:26 pm
- My devices: iPhone 4 to 6+,iPad mini to iPad air 2
Re: Mod funtion?
Thanks!
-
- Posts: 814
- Joined: Tue Apr 09, 2013 12:23 pm
- My devices: iPhone,iPad
Windows - Location: Groningen, Netherlands
- Flag:
Re: Mod funtion?
If there weren't a % operator, you would provide for your own function like:Is there a mod function or a way to add one?
a mod b
a - (b * (a / b))
Eg. 35 mod 3 = 2
Code: Select all
print mod(35,3)
def mod(a,b)
return a-b*floor(a/b)
end def
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.
-
- Posts: 167
- Joined: Wed Oct 22, 2014 3:26 pm
- My devices: iPhone 4 to 6+,iPad mini to iPad air 2
Re: Mod funtion?
Thanks!!