Skip to content

Commit 940fc41

Browse files
committed
encoding.binary: little_endian_f32_at
1 parent 605c43d commit 940fc41

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

vlib/builtin/builtin.c.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,6 @@ pub fn free(ptr voidptr) {
622622
// memdup dynamically allocates a `sz` bytes block of memory on the heap
623623
// memdup then copies the contents of `src` into the allocated space and
624624
// returns a pointer to the newly allocated space.
625-
626625
@[unsafe]
627626
pub fn memdup(src voidptr, sz isize) voidptr {
628627
$if trace_memdup ? {

vlib/encoding/binary/little_endian.v

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,11 @@ pub fn little_endian_put_u64_at(mut b []u8, v u64, o int) {
151151
pub fn little_endian_put_u64_end(mut b []u8, v u64) {
152152
little_endian_put_u64_at(mut b, v, b.len - 8)
153153
}
154+
155+
@[direct_array_access; inline]
156+
pub fn little_endian_f32_at(b []u8, o int) f32 {
157+
_ = b[o] // bounds check
158+
_ = b[o + 3] // bounds check
159+
u := u32(b[o]) | (u32(b[o + 1]) << u32(8)) | (u32(b[o + 2]) << u32(16)) | (u32(b[o + 3]) << u32(24))
160+
return *(&f32(&u))
161+
}

0 commit comments

Comments
 (0)