Requesting support for float32 in Motoko

I would like to request that Motoko implements supports the float32 Candid type.

If I understand it correctly, the Motoko Float maps on the Candid float64, and it does not support float32.

This is inconvenient, because the float32 type is very common in the C/C++ canisters that I am writing, and I now have to create a special interface to allow it being called from Motoko.

In more detail: I am porting C/C++ code to canisters that I then call from Motoko. The Candid interface designed for the C/C++ canisters was build from the inside out, and it uses float32 for the LLM Prompt with variables temperature & topp.


I was wondering when someone would ask for this… Do you want full numeric support for the Float32 type in Motoko or would it be enough to import/export Candid float32 as Float64 with some information loss when exporting as Candid float32 (if that even makes sense).

Does your API merely produce float32s (as results) or also consume them (as arguments)? If the former, we could simply convert them to Float64 on the Motoko side, with no loss of precision. If the latter, we would need Motoko to be able to create Float32 values, which could be a lot more work depending on how much support we provide.


An MVP might be to provide a Float32 type with no literals or operations and conversions from Float64 ↔ Float32. Still a fair whack of work though…

1 Like

In my case I both consume and produce Float32. A conversion to/from Candid Float32 is all I would need.

Thanks for the answer!