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 Professional Discussion / Is there a quicker floating point 'MOD' function?

Author
Message
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th Aug 2011 00:00
I've done this temporarily:


Does anyone know a quicker way?

The built in 'MOD' only works with integers...

Warning! May contain Nuts!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Aug 2011 01:03


You may need to tweak it to get the responses you require when you include negatives though.

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th Aug 2011 01:29
I am including negative numbers and done a bit of googling so I'm hoping it will work. Cheers...

Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th Aug 2011 01:40 Edited at: 17th Aug 2011 02:23

I'll implement this into your code IanM... Thanks...

EDIT: Going to finish up what I was doing then try out this...


Warning! May contain Nuts!
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 17th Aug 2011 23:41
Nope the above function didn't work, but I did get my program working anyway by adding the most negative value to the current value (extents) making all results a positive...

Warning! May contain Nuts!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 18th Aug 2011 06:47 Edited at: 18th Aug 2011 06:49
Quote: "The built in 'MOD' only works with integers..."

Huh? I could have sworn it works with floats, and I thought I had tested this out before...

[edit]
also, I don't think % is the modulo operator in DBPro, maybe %% is. Type in "mod" instead. so instead of 3.4%1, type 3.4 mod 1

sorry I can't test this out right now :\


Why does blue text appear every time you are near?
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 18th Aug 2011 10:53
As Neuro Fuzzy said, It appears the built in MOD works with floats. Unless I am missing something in my test. And handles negative ints



Your signature has been erased by a mod please reduce it to 600 x 120.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 18th Aug 2011 13:05
It does work!

Very likely when I tried it the other day I did something silly like a typo and was only getting integer values. I just tried it now on a blank page and it is '%%' that also work.

Thanks... (even after removing tons of typos from my program I didn't go back and check that one)

Warning! May contain Nuts!
Mistrel
Retired Moderator
20
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 18th Aug 2011 13:16
You could try calling fmod from msvcrt.dll to see if it's faster, as this implementation is most likely written in C or possibly even assembly.

Login to post a reply

Server time is: 2026-07-10 13:44:46
Your offset time is: 2026-07-10 13:44:46