| 574 | const int MaxAbsInt16 = 0x4000; |
| 575 | // we want to have 0.5 represented exactly |
| 576 | // we also want to keep some reserve range in case small overflow will occur |
| 577 | |
| 578 | inline int EncodeFloat16(float x) |
| 579 | { |
| 580 | constexpr float networkOrientationTolerance = 1e-3f; |
| 581 | if (x < -1.0f || x > 1.0f) |
| 582 | { |
| 583 | NET_ERROR(std::isfinite(x)); |
| 584 | NET_ERROR(x >= -1.0f - networkOrientationTolerance); |
| 585 | NET_ERROR(x <= +1.0f + networkOrientationTolerance); |
| 586 | saturate(x, -1.0f, +1.0f); |
| 587 | } |
| 588 | int r = toInt(MaxAbsInt16 * x); |
| 589 | saturate(r, -MaxAbsInt16, +MaxAbsInt16); |
| 590 | return r; |
| 591 | } |
| 592 | |