8 bit signed float possible?

Christian S <>
Sat Jun 17 14:27:35 CEST 2006


On 6/17/06, Andrew Lentvorski <> wrote:
> Ericsson wrote:
> > 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.


> 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

And once that is understood you can of course deconstruct 8 bits into
small integers and construct a floating point number out of them
yourself.

Given 1 sign bit, 2 exponent bits and 5 mantissa bits you can have 32
different fractions between 1.0 and 0.0, and you have have (as a
suggestion) 10^1, 10^0, 10^-1, 10^2
multipliers from the exponent bit. Then the closest you can come to 3.14 is
10*(1.0/32) * 10^1 = 0.3125 * 10^1 = 3.125.

Good enought for government work, or what is it they say?



More information about the erlang-questions mailing list