[GD-General] Some portability questions
Brought to you by:
vexxed72
From: Brian H. <bri...@py...> - 2002-11-08 18:58:27
|
Okay, these are fun ones. Let's do the easy one first. 1.) How do you portably and safely byte swap a floating point value? Disregarding the whole "some architectures aren't IEEE and/or don't have 32-bit floats" issue, it seems like the right way to do this safely is to cast the bits to an integer value, swap those, and store out as integer. To load a floating point value, you perform the inverse, and pray that you didn't load some invalid thing that will generate an FP exception on some systems. I hadn't really thought about this until I started working on POSH (Portable Open Source Harness). 2.) How do you cleanly handle architectures where, say, all data types are either 1-byte or 8-bytes. The Cray and early 21064 Alphas were like this (actually, I don't think early Alphas even had atomic <8-byte read/writes). Answer: it's a Cray, dude. Shut up. If I can't figure out a clean, safe way of handling this, I may just punt on those architectures. Brian |