Webassembly how to get pointer or reference of f64

687 views Asked by At

Is there any method in assemblyscript which get the pointer of type f64?

It works:

let c: ClassA;
changetype<usize>(c)

It don't work

let f:f64
changetype<usize>(f)
1

There are 1 answers

2
sirwillem On BEST ANSWER

Primitive number types aren't heap allocated. The are on the stack of the current function as a local variable. If you want to allocate it you can use __alloc, e.g.

let f_ptr = __alloc(sizeof<f64>());
store<f64>(f_ptr, f);

If you are trying to pass the f64 to javascript you don't have to use indirection since it is one of the possible types in import/exports, along with integers.