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 / Wrapvalue math function

Author
Message
Brightside_
6
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 9th Nov 2019 22:27
Hi!
Have anybody math function such as wrapvalue but with custom limits (not 0 and 360) ?
Also I need this working with neagative values.
Mage
13
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 9th Nov 2019 22:36
There is a division command that returns the "remainder" of division. This could be used to do what you need.

For example 370 degrees divided by 360 leaves a remainder of 10 which would be the normal wrapped result.



I cannot test this at the moment. I am not sure 100% if there will be issues with decimal/float operations. Also I am not 100% sure about negative numbers.
This likely will work however.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Kuper
12
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 12th Nov 2019 21:36
Works fine for me.

sladeiw
11
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 13th Nov 2019 18:55
IanM's matrix1 plugin has just this function:

Value = WRAP( Current Value, Min Value, Max Value)

Description
This function will return the Current Value unless it is outside of the range specified. If it is outside the range the function will wrap the value around to bring it back within the range.
Brightside_
6
Years of Service
User Offline
Joined: 27th Oct 2013
Location:
Posted: 14th Dec 2019 14:10
Both ways work well.Thanks!

Login to post a reply

Server time is: 2020-08-03 16:43:48
Your offset time is: 2020-08-03 16:43:48