assemblyscript

Webassembly how to get pointer or reference of f64


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)

Solution

  • 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.