| 49 | } |
| 50 | |
| 51 | static int piecewise_normalize(float score, float left, float right, |
| 52 | float threshold, int new_left, int new_right, |
| 53 | int new_threshold) { |
| 54 | if (!(score >= left && score <= right)) { |
| 55 | return new_left; |
| 56 | } |
| 57 | int ret; |
| 58 | if (score < threshold) { |
| 59 | ret = ((score - left) / (threshold - left) * |
| 60 | (new_threshold - new_left) + |
| 61 | new_left); |
| 62 | if (ret < new_left) |
| 63 | ret = new_left; |
| 64 | if (ret >= new_threshold) |
| 65 | ret = new_threshold - 1; |
| 66 | } else { |
| 67 | ret = ((score - threshold) / (right - threshold) * |
| 68 | (new_right - new_threshold) + |
| 69 | new_threshold); |
| 70 | if (ret <= new_threshold) |
| 71 | ret = new_threshold + 1; |
| 72 | if (ret > new_right) |
| 73 | ret = new_right; |
| 74 | } |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | /// the original seed |
| 79 | static unsigned int seed = 0x0F3A286E; |