Oxygen Basic

Programming => Problems & Solutions => Topic started by: Aurel on April 24, 2015, 02:31:40 AM

Title: modulus - integer division ?
Post by: Aurel on April 24, 2015, 02:31:40 AM
when i try to implement modulus division in my interpreter i see that something is
wrong modulo operator ,is that true or i don't know something  ???
this code exit with 9  ::)

Code: [Select]
'modulus - integer division ?
float a,b
int m
a=7:b=2
m=a % b
print str(m)

.
Title: Re: modulus - integer division ?
Post by: Aurel on April 24, 2015, 02:49:02 AM
hmm i found that i must use function
mod(a,b)   ...right?
BUT when i try this i get wrong result
mod(7,2) should be 3 not 1  ?
Code: [Select]
'modulus - integer division ?
float a,b
float m
a=7:b=2
m=mod(a,b)
print str(m)

.
Title: Re: modulus - integer division ?
Post by: Charles Pegge on April 24, 2015, 03:23:22 AM

Code: OxygenBasic
  1. print 7/2      'result 3.5 (float division)
  2. print 7\2      'result 3 (integer division)
  3. print mod(7,2) 'result 1 (remainder of integer division)
  4.  
Title: Re: modulus - integer division ?
Post by: Aurel on April 24, 2015, 04:00:38 AM
wait ....
so i must use backslash ....i never know  ::)
ok ..thanks Charles  ;)
Title: Re: modulus - integer division ?
Post by: Aurel on April 24, 2015, 04:26:44 AM
well
directly in o2 result is ok - 3
but when i add it to interpreter then i get weird result ...
oh man... ::)

yes something is wrong ...
it is ok if second operand is number or variable but problem begin
when is second operator function()
like in my case:

Quote
'modulus -> integer division
    If Look = "%"   
      Gosub getchar
      iValue = Value \ Factor()
      print "Modulo:" + str(iValue)
      Value = iValue   
    End If

sorry Charles but i think that you must fix this...
thanks...
Title: Re: modulus - integer division ?
Post by: Charles Pegge on April 24, 2015, 06:56:44 AM
What is factor?
Title: Re: modulus - integer division ?
Post by: Aurel on April 24, 2015, 07:47:06 AM
factor is a function which return a value ..nothing special
i will give you example :
Title: Re: modulus - integer division ?
Post by: Aurel on April 24, 2015, 07:52:11 AM
try this :
Code: [Select]
'modulus - integer division ?
float a,b
float m
a=7:b=2
m=a\b
print str(m) + " Ok"

function factor(float f) as float
float ff
ff=f+1
return ff
end function

m= a \ factor(1) 'use func factor()
print str(m) + " weird?"
Title: Re: modulus - integer division ?
Post by: Charles Pegge on April 24, 2015, 09:05:38 AM
I get a result of 3 and 3, which is correct
Title: Re: modulus - integer division ?
Post by: Aurel on April 24, 2015, 01:13:01 PM
ahh i mean integer division not the rest of division...
Charles...
i found that my wrong result is because i use older oxygen .dll 479kB
so i use new 472kB ...i am not sure is this latest version but now work
properly and give me result 3... ;)
Title: Re: modulus - integer division ?
Post by: Aurel on April 24, 2015, 01:29:54 PM
noooo
With new version of oxygen dll i have problem with strings in fact if i increase window
title text then interpreter don't want execute code ...geez  ::)
where i can find latest oxygen dll?
Title: Re: modulus - integer division ?
Post by: Aurel on April 24, 2015, 01:38:08 PM
ok i found latest (i hope) from here :
http://www.oxygenbasic.org/forum/index.php?topic=1298.0
and it looks that work properly
Title: Re: modulus - integer division ?
Post by: Charles Pegge on April 24, 2015, 02:01:52 PM
The wizard at the top of the page always links to the latest version.

And in this topic:

http://www.oxygenbasic.org/forum/index.php?topic=749.0