Author Topic: modulus - integer division ?  (Read 3643 times)

0 Members and 1 Guest are viewing this topic.

Aurel

  • Guest
modulus - integer division ?
« 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)

.

Aurel

  • Guest
Re: modulus - integer division ?
« Reply #1 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)

.

Charles Pegge

  • Guest
Re: modulus - integer division ?
« Reply #2 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.  

Aurel

  • Guest
Re: modulus - integer division ?
« Reply #3 on: April 24, 2015, 04:00:38 AM »
wait ....
so i must use backslash ....i never know  ::)
ok ..thanks Charles  ;)

Aurel

  • Guest
Re: modulus - integer division ?
« Reply #4 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...

Charles Pegge

  • Guest
Re: modulus - integer division ?
« Reply #5 on: April 24, 2015, 06:56:44 AM »
What is factor?

Aurel

  • Guest
Re: modulus - integer division ?
« Reply #6 on: April 24, 2015, 07:47:06 AM »
factor is a function which return a value ..nothing special
i will give you example :

Aurel

  • Guest
Re: modulus - integer division ?
« Reply #7 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?"

Charles Pegge

  • Guest
Re: modulus - integer division ?
« Reply #8 on: April 24, 2015, 09:05:38 AM »
I get a result of 3 and 3, which is correct

Aurel

  • Guest
Re: modulus - integer division ?
« Reply #9 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... ;)

Aurel

  • Guest
Re: modulus - integer division ?
« Reply #10 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?

Aurel

  • Guest
Re: modulus - integer division ?
« Reply #11 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

Charles Pegge

  • Guest
Re: modulus - integer division ?
« Reply #12 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
« Last Edit: April 24, 2015, 02:15:05 PM by Charles Pegge »