8 bit signed float possible?

Andrew Lentvorski bsder@REDACTED
Sat Jun 17 00:48:57 CEST 2006


Ericsson wrote:
> Hi!
>  
> 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?

Yes.

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 
bit.

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.":

http://docs.sun.com/source/806-3568/ncg_goldberg.html

-a



More information about the erlang-questions mailing list