I64 <-> u64 mapping

Is there a simple way to map i64 <-> u64 such that:

  1. for values they both represent, the maping preserves value

  2. the mapping is 1-1

?

You can convert between them using as which effectively transmute them and has those 2 properties you mentioned.

1 Like

The mapping used by as casting or other bit-for-bit reintepretation in Rust is two's complement.

1 Like