8 bit signed float possible?
Sat Jun 17 00:48:57 CEST 2006
> I'm trying to construct an eight bit signed float in binary format:
> Float = 3.14.
> Bin = <<Float:8/signed-float>>.
> This only give badarg error. Is 8 bits too small for a float?
Erlang doesn't support floats other than 32 and 64.
However, I recommend that you do some homework on understanding floating
point. An 8-bit float would simply be too small to contain 3.14. You
need about 8 bits of mantissa and 1 bit of sign to contain that number.
That would only leave 7 bits for the exponent of which 1 bit is a sign
Even a 16-bit floating point number would be pushing it.
I heartily recommend David Goldberg's "What Every Computer Scientist
Should Know About Floating Point.":
More information about the erlang-questions