new type

J

jimmij

Most of compilers have 32-bits size of float.
Is it possible to create "short float" - 16 bits?
 
L

LR

jimmij said:
Most of compilers have 32-bits size of float.

Is it possible to create "short float" - 16 bits?

Sorry, but what do you mean by create?

If you want, you could create a class that is a "short float" type,
although thats not many bits. What maximum precision and magnitude
would you want your type to have?

I don't think I've ever heard of hardware supporting a 16 bit float
type, but for all I know it exists.

Whats your reason for asking?

LR
 
J

jimmij

LR said:
If you want, you could create a class that is a "short float" type,
although thats not many bits. What maximum precision and magnitude
would you want your type to have?

I don't think I've ever heard of hardware supporting a 16 bit float
type, but for all I know it exists.

Whats your reason for asking?

Well, I'm writing a program which operates on many variables and at some
point there is problem with shortage of memory. Since precision doesn't
matter for me (16 bits is good enough) I'm looking for smaller float
type.
Can you give me a hint how to build such class?
 
L

LR

jimmij said:
Well, I'm writing a program which operates on many variables and at some
point there is problem with shortage of memory.

How many variables do you have? Do you have something on the order of
1e6 variables? 1e9? 1e12? More?

Since precision doesn't
matter for me (16 bits is good enough)

It has to matter somewhat. A 16 bit float won't give you 16 bits of
precision. If the exponent takes two (2) bits, no matter how
unrealistic that is, then you'd have 14 bits to represent the mantissa.
Fewer are far more likely.

But if precision really doesn't matter, then it's reasonable to ask,
what is the smallest number of bits that you could use to store your
data. And what do you really need. Could you use something that just
stored the exponent?
> I'm looking for smaller float type.
Can you give me a hint how to build such class?

Google and Wikipedia are your friends. I'd start here:
http://en.wikipedia.org/wiki/Floating_point There are some interesting
looking links there too.

Frankly, I think this might be a good learning experience, but I suspect
that it may not be the answer you're looking for. To begin with if you
have so many variables that you're running out of memory then the speed
hit you're going to take doing FP emulation is likely to be pretty bad.

Just a guess, of course, since I don't know what your application is,
but perhaps you could rewrite it to page out some of your variables to
mass storage or perhaps you may want to look into some sort of cluster.

LR
 
G

Gianni Mariani

jimmij said:
Most of compilers have 32-bits size of float.
Is it possible to create "short float" - 16 bits?

short float is not an allowable type.

struct short_float
{
... stuff that looks like a 16 bit float.
};

is allowable but you would need to fill in the blanks.
 
J

Jerry Coffin

Most of compilers have 32-bits size of float.
Is it possible to create "short float" - 16 bits?

Sure, it's possible. Most places I've seen it used, it's call a 'half-
precision float' or just a 'half'.

Depending on what you need, it's also possible to use a fixed point
number, which is basically just an integer with a scaling factor
applied. This is generally faster and easier to implement.
 
J

Jerry Coffin

[ ... ]
I don't think I've ever heard of hardware supporting a 16 bit float
type, but for all I know it exists.

It does -- a fair amount of semi-recent graphics hardware (e.g. nVidia
7xxx series) supported exactly this.
 
L

LR

Jerry said:
[ ... ]
I don't think I've ever heard of hardware supporting a 16 bit float
type, but for all I know it exists.

It does -- a fair amount of semi-recent graphics hardware (e.g. nVidia
7xxx series) supported exactly this.


Thanks very much for that. Learn something new every day.

A little googling turned up links to an implementation of a 16 bit real
type called half used by Industrial Light and Magic as part of some open
source code called OpenEXR. I suspect the OP may find searching for
this useful.

There are even eight and six(!) bit formats
http://home.earthlink.net/~mrob/pub/math/floatformats.html (with some
interesting looking links) although these are for educational purposes.

Thanks again.

LR
 
J

James Kanze

[ ... ]
I don't think I've ever heard of hardware supporting a 16 bit float
type, but for all I know it exists.
It does -- a fair amount of semi-recent graphics hardware (e.g. nVidia
7xxx series) supported exactly this.

And telephone systems use 7 (USA) or 8 (Europe) bit floating
point to digitalize voice: 1 bit sign, 3 bits exponent, and 4
bits mantissa (in Europe). With an 8 K sample rate, it gives
better fidelity than the old analog systems it replaces. I'm
also sure that there is special hardware available for at least
some operations on these types: conference calls require
addition, and decoding touch tone phones uses an FFT.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,654
Latest member
LannySinge

Latest Threads

Top