| 343 | } |
| 344 | |
| 345 | void BitStream::writeFloat(F32 f, S32 bitCount) |
| 346 | { |
| 347 | auto maxInt = (1U << bitCount) - 1; |
| 348 | U32 i; |
| 349 | if (f < POINT_EPSILON) |
| 350 | { |
| 351 | // Special case: <= 0 serializes to 0 |
| 352 | i = 0.0f; |
| 353 | } |
| 354 | else if (f == 0.5) |
| 355 | { |
| 356 | // Special case: 0.5 serializes to maxInt / 2 + 1 |
| 357 | i = maxInt / 2 + 1; |
| 358 | } |
| 359 | else if (f > (1.0f- POINT_EPSILON)) |
| 360 | { |
| 361 | // Special case: >= 1 serializes to maxInt |
| 362 | i = maxInt; |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | // Serialize normally but round the number |
| 367 | i = static_cast<U32>(roundf(f * maxInt)); |
| 368 | } |
| 369 | writeInt(i, bitCount); |
| 370 | } |
| 371 | |
| 372 | F32 BitStream::readFloat(S32 bitCount) |
| 373 | { |
no outgoing calls
no test coverage detected