Scale numbers to be <= 255?

前端 未结 13 2214
生来不讨喜
生来不讨喜 2021-02-05 18:39

I have cells for whom the numeric value can be anything between 0 and Integer.MAX_VALUE. I would like to color code these cells correspondingly.

If the val

13条回答
  •  伪装坚强ぢ
    2021-02-05 19:06

    I figured a log fit would be good for this, but looking at the results, I'm not so sure.

    However, Wolfram|Alpha is great for experimenting with this sort of thing:

    I started with that, and ended up with:

    r(x) = floor(((11.5553 * log(14.4266 * (x + 1.0))) - 30.8419) / 0.9687)
    

    Interestingly, it turns out that this gives nearly identical results to Artelius's answer of:

    r(x) = floor(255 * log(x + 1) / log(2^31 + 1)
    

    IMHO, you'd be best served with a split function for 0-10000 and 10000-2^31.

提交回复
热议问题