Corrected float reading

This commit is contained in:
hch12907 2018-08-05 15:42:21 +08:00
parent 2ac3746d30
commit 1ac9c98300
2 changed files with 8 additions and 4 deletions

View file

@ -27,12 +27,14 @@ public:
/// Read/write floats - wrappers around read/write uword.
f32 read_float(const size_t offset)
{
return static_cast<f32>(read_uword(offset));
uword raw = read_uword(offset);
return *reinterpret_cast<f32*>(&raw);
}
void write_float(const size_t offset, const f32 value)
{
write_uword(offset, static_cast<uword>(value));
f32 raw = value;
write_uword(offset, *reinterpret_cast<uword*>(&raw));
}
/// ByteBusMappable overrides.

View file

@ -24,12 +24,14 @@ public:
/// Read/write floats - wrappers around read/write uword.
f32 read_float()
{
return static_cast<f32>(read_uword());
uword raw = read_uword();
return *reinterpret_cast<f32*>(&raw);
}
void write_float(const f32 value)
{
write_uword(static_cast<uword>(value));
f32 raw = value;
write_uword(*reinterpret_cast<uword*>(&raw));
}
/// Bitfield extraction/insertion.