Copy bytes to a float. See "include/loader/filemgr.h".
| 224 | |
| 225 | // Copy bytes to a float. See "include/loader/filemgr.h". |
| 226 | Expect<float> FileMgr::readF32() { |
| 227 | if (Status != ErrCode::Value::Success) { |
| 228 | return Unexpect(Status); |
| 229 | } |
| 230 | // Set the flag to the start offset. |
| 231 | LastPos = Pos; |
| 232 | |
| 233 | uint32_t Buf = 0; |
| 234 | Byte Byte = 0x00; |
| 235 | // Check whether reading exceeds the data or section boundary. |
| 236 | EXPECTED_TRY(testRead(4)); |
| 237 | for (uint32_t I = 0; I < 4; I++) { |
| 238 | Byte = Data[Pos++]; |
| 239 | Buf |= (Byte & UINT32_C(0xFF)) << (I * UINT32_C(8)); |
| 240 | } |
| 241 | float Result; |
| 242 | static_assert(sizeof(Buf) == sizeof(Result)); |
| 243 | std::memcpy(&Result, &Buf, sizeof(Result)); |
| 244 | return Result; |
| 245 | } |
| 246 | |
| 247 | // Copy bytes to a double. See "include/loader/filemgr.h". |
| 248 | Expect<double> FileMgr::readF64() { |