Normalizing from [0.5 - 1] to [0 - 1]

前端 未结 6 1544
自闭症患者
自闭症患者 2021-01-30 02:45

I\'m kind of stuck here, I guess it\'s a bit of a brain teaser. If I have numbers in the range between 0.5 to 1 how can I normalize it to be between 0 to 1?

Thanks for a

6条回答
  •  时光说笑
    2021-01-30 03:24

    Subtract 0.5 (giving you a new range of 0 - 0.5) then multiply by 2.

    double normalize( double x )
    {
        // I'll leave range validation up to you
        return (x - 0.5) * 2;
    }
    

提交回复
热议问题