encoding.binary: little_endian_f32_at

This commit is contained in:
Alexander Medvednikov 2024-07-01 14:08:37 +03:00
parent 605c43df75
commit 940fc41c19
2 changed files with 8 additions and 1 deletions

View File

@ -622,7 +622,6 @@ pub fn free(ptr voidptr) {
// memdup dynamically allocates a `sz` bytes block of memory on the heap
// memdup then copies the contents of `src` into the allocated space and
// returns a pointer to the newly allocated space.
@[unsafe]
pub fn memdup(src voidptr, sz isize) voidptr {
$if trace_memdup ? {

View File

@ -151,3 +151,11 @@ pub fn little_endian_put_u64_at(mut b []u8, v u64, o int) {
pub fn little_endian_put_u64_end(mut b []u8, v u64) {
little_endian_put_u64_at(mut b, v, b.len - 8)
}
@[direct_array_access; inline]
pub fn little_endian_f32_at(b []u8, o int) f32 {
_ = b[o] // bounds check
_ = b[o + 3] // bounds check
u := u32(b[o]) | (u32(b[o + 1]) << u32(8)) | (u32(b[o + 2]) << u32(16)) | (u32(b[o + 3]) << u32(24))
return *(&f32(&u))
}