Computer Science Canada

using mod with real values

Author:  Prince [ Thu Mar 27, 2003 11:38 am ]
Post subject:  using mod with real values

unless this just isnt possible, im getting an error saying that assigned value is the wrong type

code:

function modX (x, y : real) : int
    var imod : int
    imod := x mod y % error given for y
    result imod
end modX


is there any way to complete this without changing the variable type?

Author:  Blade [ Thu Mar 27, 2003 11:41 am ]
Post subject: 

you cant use real numbers in coordinates or sizes or anything like that, they have to be integers, because you cant use half of a pixel..

Author:  Tony [ Thu Mar 27, 2003 12:11 pm ]
Post subject: 

well mod just tells you if it devides compleatly into the number.

so

code:

function modReal(num1:real, num2:real):real

if (num1/num2) = round(num1/num2) then
result 0
else
result (num1/num2) - floor(num1/num2)
end if

end modReal

put modReal(10.2, 2.5)


the result should be 0.08... code is theoretical as I dont have compiler nearby at the moment... I need someone to confirm that this works

Author:  Blade [ Thu Mar 27, 2003 12:22 pm ]
Post subject: 

ah, sorry man, i misunderstood the question.. but yea, tony, i tested it and it works

Author:  Prince [ Thu Mar 27, 2003 5:10 pm ]
Post subject: 

thnx tony... it works btw but it still sends out decimal numbers (unless thats wat u wanted it to do) so im gonna try and fix that part

Author:  Tony [ Thu Mar 27, 2003 6:26 pm ]
Post subject: 

mod gives you a remainder of the division.

modReal acts in the same way as mod, but since both numbers can be real now, so is the remainder.


: