I am porting some complex C++ code to Julia. The one part that has me really perplexed is how to port the C++ concept of a union. If you aren’t familiar with union, its like a structure, but all of the members share the exact same memory space. So an array of two UInt32s and a Float64 are supposed to be in the same 8 bytes. The code I am looking at loads the array with a couple of Ints, does some bit shifting and then reads the resultant Float.
In Julia I have been doing the manipulation of the ints, getting the bit patterns, and concatenating them and parsing as a float. That doesn’t work. I guess I need to talk to someone that understands the internal representation of data in a union to help me figure out a way of replicating the results.
I fully admit this is straight up sorcery. No one should write an int array to a union and then read it as a float. However, it’s the code I have to port so… have pity on me.