I was looking for the nim equivalent to the go function math.Float64Bits and none of my searches turned up anything (bad choices of search, no doubt)
Anyway the following worked - but I am wondering if there is a better NIM way:
proc float64Bits(x:float64):int64 =
var x = x
var xi: int64
moveMem(addr(xi),addr(x),8)
return xi
since using moveMem makes me nervous
If you want to transform one value to another while still keeping the same bit pattern, use a cast.
let
i = 5.4
g = cast[float](i)
To be sure I understand, if there was:
then x.addr and (cast[float64](x)).addr would be the same???
Would
result in cast[int32](w) having the value 515 - assuming little endian byte order? I realize that would be highly non-portable.