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 / [SOLVED] Proportions function?

Author
Message
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 26th Oct 2021 22:01
hi everyone, I'm used to using the "map" function when programming with arduino. This function is used to obtain a mathematical proportion.

EXAMPLE to understand what I mean:



Description of MAP function:
Re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.
Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain() function may be used either before or after this function, if limits to the ranges are desired.
Note that the "lower bounds" of either range may be larger or smaller than the "upper bounds" so the map() function may be used to reverse a range of numbers, for example
y = map(x, 1, 50, 50, 1)


Ok, i can't find a counterpart in darkbasic; do you know a quick solution? Thankyou!

The author of this post has marked a post as an answer.

Go to answer

Bored of the Rings
User Banned
Posted: 27th Oct 2021 10:05 Edited at: 27th Oct 2021 13:15
I would just create a function in DBPro that does the calculation:

convert the Arduino function :
long map(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

to a DBPro function:

function map(x as dword, in_min as dword, in_max as dword, out_min as dword, out_max as dword)
r as dword
r = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
endfunction r

let me know if I've misunderstood, but as a stats programmer who uses SAS, this is what I would do in DBPro as there isn't a function / command that does this.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 28th Oct 2021 16:22 Edited at: 28th Oct 2021 16:24
Hi Bored of the Rings! It seems to be exactly what I need! I try it and I'll tell you the result!
Meanwhile ThankYou!

Bored of the Rings
User Banned
Posted: 28th Oct 2021 16:51
no problem, proportions and probabilities and other statistical programming stuff in the clinical trial world is what I do. happy to help
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Alduce
21
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 28th Oct 2021 17:05
This post has been marked by the post author as the answer.
Bored of the Rings you helping me SOOO MUTCH!

Login to post a reply

Server time is: 2024-04-23 09:48:27
Your offset time is: 2024-04-23 09:48:27