Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Is there a modulus function in DB ??

Author
Message
BarZoule
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 26th Nov 2002 09:40
if you don't remember what is a modulus, it's the rest of a division.
Example:
10 mod 3 = 1
4 mod 2 =0
it can be very useful for alternances or sawtooth waves.
heartbone
21
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 26th Nov 2002 09:56
Not in DB1.
But there is in DBPro.
BarZoule
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 26th Nov 2002 10:06
okay, so that mean i'll have to make make it myself :\

Shadow
21
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 28th Nov 2002 18:36
Don't you mean a remainder?
A modulus is what you get from
ChipOne
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Canada
Posted: 28th Nov 2002 19:26
Shadow: that's not the same. abs returns the absolute value (essentially, the unsigned value) of the parameter passed into it.

the formula for calculating x mod y is:
x-y*int(x/y)

cheers.

-= i only do what my rice krispies tell me to do =-
Zooker
21
Years of Service
User Offline
Joined: 27th Oct 2002
Location: United States
Posted: 28th Nov 2002 20:44
Go to MatEdit.com and Download TDK_Man's StrFunctions! Very Good stuff and the price is Rite!!!

It took Years to Make Me this Stupid!
hexGEAR
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 28th Nov 2002 21:53
(4-2)*int(4/2) = 4
4 mod 2 = 0

your birth was a blessing, sent to live and die on earth as a lesson, we each have a star all you have to do is find it, once you do, everyone who sees it will be blinded - DMX
hexGEAR
21
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 28th Nov 2002 21:55
there has gasta be an easier way of doing this:



basically, it takes in two numbers where num1 > num2, and returns the mod. haven't tested it out yet for -ve numbers.

your birth was a blessing, sent to live and die on earth as a lesson, we each have a star all you have to do is find it, once you do, everyone who sees it will be blinded - DMX
ChipOne
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Canada
Posted: 28th Nov 2002 22:17


you didn't read the formula properly
try again, but don't invent brackets on your own:
4-2*int(4/2)
not:
(4-2)*int(4/2)

silly wabbit!

-= i only do what my rice krispies tell me to do =-
ChipOne
21
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Canada
Posted: 28th Nov 2002 22:19
again, if that wasn't clear this works:
x-y*int(x/y)

this does not work:
(x-y)*int(x/y)

you can't use the brackets. sorry i can't edit my earlier post to make this more clear.

-= i only do what my rice krispies tell me to do =-
Shadow
21
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 29th Nov 2002 18:38
In English English (as opposed to american english) modulus means absolute. I have no idea what your thing is or what it's for.
Bitmap
21
Years of Service
User Offline
Joined: 20th Oct 2002
Location: Latvia
Posted: 29th Nov 2002 18:53
mod = original-(original/num)*num

I do it like this

thy boss
Dean
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Canada
Posted: 30th Nov 2002 04:58
what can a mod be used for?


''Mmmm.. Tastes like Nazca!''
heartbone
21
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 30th Nov 2002 06:45
imagine a grid 22 x 22
(0-21 by 0-21)
and you are on square # 144
what is the x and y grid coords?

y= 144/22
x= 144 mod 22
BarZoule
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 1st Dec 2002 10:14
hey thanks all of you !

BTW not-so-long after i posted this i made my own MOD function, in the shape X-(Y*int(X/Y))

About the British English i didn't know modulus meant absolute. I was effectively talking about the remainder of a division.

About its applications, it is really usefull for any 'sawtooth' function, witch is easily tranformable to a 'square' function. (note: square like in techno music waveform, not like the sqr() function)

sawtooth: /|/|/|/|
so from an input like 12345678910....
you can have 123412341234....

square: _-_-_-_-_....
so from an input like 12345678910....
you can have 0000111100001111....

I let you imagine all the possible uses of this in a game !

-BarZoule

Login to post a reply

Server time is: 2024-04-19 21:07:39
Your offset time is: 2024-04-19 21:07:39