Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed point processing: what is the difference between uint16_t and uint_fast16_t?

Tags:

c

fixed-point

I have a 16 bit fixed point processor and I want to do fixed point processing with it. I'm looking for the correct datatype to use for unsigned 16 bit ints..

My question is: what is the difference between a uint16_t and uint_fast16_t? (These are included in the stdint.h.) Is uint_fast16_t better since it is faster??

Thanks!!

like image 662
O_O Avatar asked Feb 10 '11 19:02

O_O


People also ask

What is the difference between int and uint16_t?

int is usually (but may not be) a 32-bit signed integer, while uint16_t is guaranteed to be an unsigned 16-bit integer.

What is a uint16_t?

uint16_t is unsigned 16-bit integer. unsigned short int is unsigned short integer, but the size is implementation dependent. The standard only says it's at least 16-bit (i.e, minimum value of UINT_MAX is 65535 ). In practice, it usually is 16-bit, but you can't take that as guaranteed.

What is uint_ fast16_ t?

uint_least16_t the smallest thing that is capable of holding a uint16. uint_fast16_t the fastest thing that is capable of holding a uint16. uint16_t exactly a uint16, unfortunately may not be available on all platforms, on any platform where is is available uint_least16_t will refer to it.


2 Answers

uint16_t is an unsigned 16-bit integer. uint_fast16_t is the fastest available unsigned integer with at least 16 bits.

like image 187
Sven Avatar answered Oct 09 '22 21:10

Sven


uint16_t is more restrictive than uint_fast16_t and uint_least16_t. Not only that the later two may be wider than 16 bits, they may also have padding bits (bits that don't account for the value such as parity bits).

This difference is even more pronounced for the signed types. Here the exact width types must use the two's complement to represent negative values.

like image 45
Jens Gustedt Avatar answered Oct 09 '22 21:10

Jens Gustedt