@bplus yes you're right PMAP is a QB45 keyword, that of Fellippe & Ashish is map!, but I have it in so much consideration that I have made a Freudian's lapsus.
so you're thinking that the earth is hollow... mmmh but in this case it is simpler to reach the center of the earth by pole's hole,is it? :)) Nevertheless I can pass my code to the NASA if you think that this is useful.
about my C++ compiling error, in the following attemps I got your results.... QB64 1.5 dev in Windows 8 Pro 64bits.
My curiosity is about the result of Normalization#... nan? Is it an alien number that comes out?
However thanks Bplus you let see nearer my code so I see now that I have translate bad this template formula
'valore normalizzato = minimoscala+
'((osservazione-MIN(intervallo))/
'(MAX(intervallo)-MIN(intervallo))*
'(massimoscala-minimoscala)
with this code
Normalize# = iNewMin + ((iValue - iMin) / (iMax - iMin) * (iNewMax - iNewMin))
as you can see the last rounded parenthesis must be put after (imax-iMin) and before * (iNewMax-iNewMin)!
a typo error!
about proportion# it has been build only for positive numbers...
but if we want adapt it to all combinations (like your example where it manages negative numbers) we must use the ABSolute value of the variable passed to it and adding at the end the iNewMin because the counting of numbers starts from there.
So here the code!
iMin = 0
iMax = 10
iNewMin = -100
iNewMax = 0
PRINT " StartValue Proportion Translation" iValue = i
dNewValue = Proportion#
dNewValue2 = Normalize#
PRINT iValue;
" "; dNewValue;
" "; dNewValue2;
" "; map!
(iValue
, iMin
, iMax
, iNewMin
, iNewMax
)
END ' local end of the program
' Delta1:Delta2 = iValue : iValue2
' iValue2 = (Delta2 * ivalue) /Delta1
' Delta1 = Absolute( iMax - iMin)
'Delta2 = Absolute(iNewMax - iNewMin)
Proportion#
= (iValue
* ABS(iNewMax
- iNewMin
)) / ABS(iMax
- iMin
) + iNewMin
'valore normalizzato = minimoscala+
'((osservazione-MIN(intervallo))/
'(MAX(intervallo)-MIN(intervallo))*
'(massimoscala-minimoscala)
Normalize# = iNewMin + ((iValue - iMin) / (iMax - iMin)) * (iNewMax - iNewMin)
FUNCTION map!
(value!
, minRange!
, maxRange!
, newMinRange!
, newMaxRange!
) map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
in this you can see that the differences between Normalize# and map! are apparents and not real, the only that stands still on is that normalize gives a double type back while map gives a single type back.
Now that you have helped me to correct my first code... do you want say me your opinion about Proportion method vs Normalize method?