5 ms·
> When sending numeric data, use a binary format. Binary representations of floating point number are a bit of a nest of vipers too, though. You can probably j
by taneq 8y ago
> When sending numeric data, use a binary format.
Binary representations of floating point number are a bit of a nest of vipers too, though. You can probably just pipe IEEE floats across the network as bytes, in practice, but it's risky.
It's probably safer in many cases to just transmit things in fixed point.
- dbaupp 8y agoI can think of a few possible problems with IEEE754-across-the-wire, such as: - not all hardware supports them - subnormal numbers are annoying - NaNs can be tricky to handle, such as signalling and (if payloads are used) security risks through NaN payloads. Which are you thinking of? Or something else?
- jcelerier 8y ago> I can think of a few possible problems with IEEE754-across-the-wire, such as: > - not all hardware supports them let's be reasonable : how many people who run architectures which don't have any float would actually send floats to them over the network ?
- gnufx 8y agoThe parent didn't say "don't have any float". I have had to translate between little endian IEEE754 and big endian IBM format, roughly copying what HDF did. Protein crystallographers invented their own binary file format rather than just using HDF, and didn't define the binary floating point format, so that the files weren't portable initially.
- taneq 8y agoI was mainly thinking of byte order issues and handling of NaN / infinities (especially if, say, you're sending a value from one computer with FPU exceptions disabled to another one with exceptions enabled), but I seem to recall reading about other subtle implementation differences which tended to mean that floats aren't always portable between different CPUs even if they're ostensibly all IEEE compliant.
- kentonv 8y agoAlmost everything uses IEEE-754. For those that don't, converting IEEE-754 to the local native format is almost certainly much easier than parsing text. Dealing with NaN-related issues is also only a couple instructions; much easier than parsing text. (Ideally, use a serialization library that already does these things.)
- gnufx 8y agoIt's too long ago to remember details, though the code may still be in use, but I remember the binary conversion being hairy and ill-defined (754 not mapping onto IBM/VAX), maybe even dependent on the FPU settings. Not that textual conversion would be well-defined either, of course.
- slededit 8y ago754 has won, as has little endian. Even PowerPC has switched. There are IBM mainframes still being made but even they are now bi-endian because they know they've lost the war.
- DerekL 8y agoYou can also use the hexadecimal floating-point textual format. 0x3.0p-2 = 0.75