I'd like to know if there is any floatN_t type available in linux (glibc) to handle
float data of different size like it's done for integers (uintN_t in stdint.h).
I need to parse the payload of a message whose type is float, but whose size
in bit can be 8, 16, 32, 64 or 128.
There are minimum sizes for these. The size for float on many machines is 32 bits, and for double 64 bits. On one of my machines, sizeof (long double) == 16 (128 bits).
I don't think glibc defines any new ones.
None of this is stopping you from doing your own floating point type representations using 8 or 16 bits, but you'll have to do it in the integer space and convert it. This isn't really that hard.
If you're passing these around on a network, you need to be very careful about the binary representations of these things, because there may be different floating point representations than what you're expecting.
There are minimum sizes for these. The size for float on many machines is 32 bits, and for double 64 bits. On one of my machines, sizeof (long double) == 16 (128 bits).
I don't think glibc defines any new ones.
I can't rely on the common size used. They must be 8,16, etc.. bits
Quote:
Originally Posted by mgessner
None of this is stopping you from doing your own floating point type representations using 8 or 16 bits, but you'll have to do it in the integer space and convert it. This isn't really that hard.
If you're passing these around on a network, you need to be very careful about the binary representations of these things, because there may be different floating point representations than what you're expecting.
HTH
I think I'm going with my own representation, although a ready-to-use would
have been appreciated. Do you have any link/suggestion?
Up to 64 bits, I could typedef uintN_t to floatN_t for containing the variable.
While for float128_t I was thinking of
but as for interpreting and producing a value I'm not sure about how to do it.
I can't rely on the common size used. They must be 8,16, etc.. bits
Using anything other than the compiler types would mean writing all your own floating point routines completely from scratch, they wouldn't work with things like printf, and you'd discard all the performance benefits of using floating point types your CPU directly supports.
Neither does sticking two 64-bit floating point numbers together a 128-bit floating point make. They're not like integers. They've got structure inside. What you'd do to make your own custom floating point types is make a bitfield structure(integers, essentially) and routines to use it.
But an 8-bit floating point number implies you don't really care that much about accuracy. Might fixed-point numbers work instead? They can't encode NaN or infinity, but they are very straightforward to use, being just integers with an assumed decimal point...
Emitrax - IEEE 754-2008 - Wikipedia, the free encyclopedia
Try reading this carefully. You cannot go creating roll-your-own floating point numbers.
What are you really trying to do? The answer to this is NOT
'I want oddball FP datatypes'
Corona has it right - you are in for world of hurt trying to roll your own. Based on your earlier questions, I'll bet custom FP datatypes are not what you want or can program with, either.
What I'm trying to do here, is to deal with some data
defined to be float with variable size (based on some other
flags of course). As I said already, this float data can be
either 8, 16, 32, 64 or 128 bit large. Don't ask me how.
That's just what the specification I'm dealing with says.
So my problem is, using a variable for containing and
interpreting this data.
How should I cope with it? I've googled but found nothing.
Embedded systems (are you writing in that environment?) sometimes use minifloat floating point objects. If I recall correctly the smallest is 16 bit, but I don't remember exactly.
I am assuming your spec did not define the internal format of your FP numbers, so minifloat is the only thing I have ever heard about. Try google for 'minifloat floating point'. There is a small library for it as well, I think.
In C++, how can I change the type with another name
For example
How can I declaring an object real which would be the same as declaring it float (5 Replies)
Hello All
Is there a way I can find out the type of RAM (DDR1 or DDR2 or DDR3), I'm using withoout opening the cabinet?
Any Windows command?
Thanks in advance. (5 Replies)
I would like to print value of key generate like this....
key_t k = ftok(".",'c');
printf("key is %d \n" , k);
Is there other way to print this type. I dont think I am getting right output which is
key is 1662074913 (shouldn't it be 6362074913) since 'c' is 63 in hex (ascii table).... (2 Replies)
Dear colleagues,
One of my friend have a problem with c code. While compiling a c program it displays a message like
"array type has incomplete element type". Any body can provide a solution for it.
Jaganadh.G (1 Reply)
Hello there,
i just want to know what are the different type of shells and the main difference betwee them. The problem is that if you try to search over the net you will find a lot of information and hence you will have no enough time to read all of them.....Anyone can help with this?? (1 Reply)
As a formem unix newbe
I Just wanted to tell you about this cool site for all you confused people.
If you need to support more than one unix type:
Use this one. It's a life saver.
http://www.unixguide.net/unixguide.shtml
here (4 Replies)