Converting Negative to Positive: Transforming -1 to 1 into 0 to 1 in Java

  • Thread starter Thread starter bitttttor
  • Start date Start date
  • Tags Tags
    Change
AI Thread Summary
To convert an evaluation factor 'a' ranging from -1 to 1 into a positive factor 'b' from 0 to 1 in Java, the approach involves shifting the interval to [0, 2] and then scaling it. Specifically, adding 1 to 'a' transforms it to the desired range, and then dividing by 2 will yield 'b'. For instance, if 'a' is 0, 'b' would equal 0.5. This method effectively allows for the computation of 'b' alongside other factors. The discussion also includes light-hearted comments about needing caffeine and sleep.
bitttttor
Messages
11
Reaction score
0
Hi,
I'm making a small app in java and part of the script retrieves an 'evaluation' factor from 'a' between -1 to 1 (e.g. 0.882) where 1 is the best and -1 is the worst.
Now, my problem in that I need to change it into a positive factor form 'b' from 0 to 1 to compute with other factors. For example if the factor is a = 0, then b = 0.5
I cannot gasp the math.

Any help would be more than welcomed.

Best
 
Physics news on Phys.org
You can shift the interval [-1, 1] up to [0, 2] and then scale it.
 
CompuChip said:
You can shift the interval [-1, 1] up to [0, 2] and then scale it.

Thanks... I need some caffeine.
 
In my time zone it was 03:45 AM when you said that, so I'd say you need some sleep. But I guess caffeine will do too :)
 
Back
Top