A little help with negative numbers please..?

Hi,
I am trying to get my brain away integer maths with negative numbers...
This works correctly when V >= 0 but not when v < 0 (or for that matter when minVal < 0).
Am I missing something, or do I have to define somewhere that the longs are ± numbers, not positive integers?
I don't have the spare cogs/RAM for any maths functions!
I am trying to get my brain away integer maths with negative numbers...
[B]VAR[/B] [B]long [/B]v, maxVal, minVal [B]long [/B]q [B]PUB [/B]Main minVal [COLOR=DarkGreen]:=[/COLOR] [COLOR=Blue]0[/COLOR] maxVal [COLOR=DarkGreen]:=[/COLOR] [COLOR=Blue]100[/COLOR] v [COLOR=DarkGreen]:=[/COLOR] [COLOR=Blue]40[/COLOR] callDoStuff [B]PUB [/B]callDoStuff q [COLOR=DarkGreen]:=[/COLOR] (v [COLOR=DarkGreen]-[/COLOR] minVal) [COLOR=DarkGreen]/[/COLOR] (maxVal - minVal) * [COLOR=Blue]270[/COLOR]In other words, getting a value proportionate to the value v over a specified range as a proportion of 270. i.e., I am looking for the result from v= -40 to be -(the result of v=+40).
This works correctly when V >= 0 but not when v < 0 (or for that matter when minVal < 0).
Am I missing something, or do I have to define somewhere that the longs are ± numbers, not positive integers?
I don't have the spare cogs/RAM for any maths functions!
Comments
but that will not bring the expected result, as I fear.
What should be the output? A value from 0 to 270 for a number between min and max val, independ of sign?
??
I don't think this is a negative number problem. Try to keep you divisions as a last step.
40/100 = 0 in Spin.
Use
q := ((v - minVal) * 270) / ((maxVal - minVal) * 270)
You could also multiply all your numbers by 1000 and then divide your final answer by 1000.
Look for pseudoreal numbers in Labs.
Duane
Thanks for the [excuse the pun] pointers - I'll keep on trying. ;-)