perl6 - Converting data in a Blob into a Num
Asked Answered
T

1

7

I've got some bytes in a blob, an immutable buffer for binary data and I am looking for a way to convert what it holds into a floating point data structure, Num, since it is the class that fits all those 3 formats that could be in the $blob

  1. IEEE Float
  2. IEEE Double
  3. IEEE Long Double

What would be the best way of doing that conversion?

Tonguetied answered 29/4, 2018 at 11:24 Comment(0)
P
10

Import NativeCall, perform a cast to a pointer of desired type and dereference the result:

use NativeCall;
nativecast(Pointer[num32], $blob).deref;
Peacoat answered 29/4, 2018 at 11:48 Comment(1)
It seems that there is not type for the IEEE Long Double? I coudn't find a num128Tonguetied

© 2022 - 2024 — McMap. All rights reserved.