Stable ABI for floating point numbers
marioortizmanero opened this issue · 2 comments
I've noticed that there's an implementation of StableAbi
for most basic types, such as i32
, u64
, etc with the impl_for_primitive_ints
macro. However, f64
isn't in that list, and neither is f32
. In fact, f64
isn't mentioned once in the whole repository.
If it helps, their size is always known as per the reference: https://doc.rust-lang.org/stable/reference/type-layout.html#primitive-data-layout. But it's true that they don't have a known representation: https://doc.rust-lang.org/stable/reference/type-layout.html#primitive-representations.
I'm guessing I have to use std::os::raw::c_double
and std::os::raw::c_float
instead of f64
, but is there any way to make this easier to use? It seems to just be an alias to Rust's type (https://doc.rust-lang.org/std/os/raw/type.c_float.html), but I'm not sure if there are any guarantees.
Thanks!
For what I've investigated, f32
and f64
are indeed FFI-safe, just like i32
or u32
. See how this code doesn't warn about FFI issues: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8eefdc9a60206b6bd2f6339c4966df9d.
So even though it doesn't seem to be listed on the reference, it's strictly defined by IEEE 754-2008, meaning that it's equivalent to c_float
and that it's stable.
Added impls of StableAbi
for f32
and f64
in the 0.10.3 patch release