T
T
Tolik2016-07-09 20:40:47
Rust
Tolik, 2016-07-09 20:40:47

Unions in Rust or how to get u32 from f32?

Actually, in C it is possible to make a union:

union {
  int32_t i_;
  float f_;
};

and I can give f_ a (any) non-integer value and then use i_ to buffer it "as is". It is this "as is" that interests me. How to do a kind of bitwise dump of a non-integer and how to do the reverse afterwards?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Orlov, 2016-07-12
@Diel

Have a look at the std::mem::transmute() function
https://doc.rust-lang.org/std/mem/fn.transmute.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question