MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / readF32

Method readF32

lib/loader/filemgr.cpp:226–245  ·  view source on GitHub ↗

Copy bytes to a float. See "include/loader/filemgr.h".

Source from the content-addressed store, hash-verified

224
225// Copy bytes to a float. See "include/loader/filemgr.h".
226Expect<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".
248Expect<double> FileMgr::readF64() {

Callers 2

loadInstructionMethod · 0.80
TESTFunction · 0.80

Calls 2

UnexpectFunction · 0.85
EXPECTED_TRYFunction · 0.50

Tested by 1

TESTFunction · 0.64