I started writing program for a new micro controller. I required to know the size of a float and double and searched in the controller data sheet but I couldn't find it. Where can I find the size? Please help.
I started writing program for a new micro controller. I required to know the size of a float and double and searched in the controller data sheet but I couldn't find it. Where can I find the size? Please help.
Very simple to determine the sizeof any data type on any system. I don't do microcontrollers, but for any hosted system:
Code:#include <stdio.h> int main(void) { printf("Float size: %zu, Double size: %zu\n", sizeof(float), sizeof(double)); return 0; }
Yes correct but before I start the actual programming is it possible to know? I am getting confused whether it is part of controller or compiler standard.
Thank you I will do it but can you please help me to understand that if there are two suppliers of compiler is it possible that one can implement float as 16 bit and the other as 32 bit. Who defines this. I only know it is 16 bit controller.
What microprocessor are you using?
Jim
It is microchip.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
Well have you looked at the documentation for the actual compiler you will be using?
If you're using mplab you may be interested in the following: Microchip Compiler Behavior with 'float', 'double' and 'long double' Data Types and for the 16 bit compiler this may be of some interest: Floating Point. Notice how a double can be either 32 bit or 64 depending on whether or not you use a certain compiler switch.
Jim
Thank you very much for the link. It was really useful. In future can I refer limits.h and float.h file to get the information?
I don't really understand why you need to worry about the size of the float or doubles, if you're worried about memory consumption use float, otherwise use double. In the case of the mplab compiler just reading the header files probably won't help since you also need to know if that variable has been defined.
Jim
OK got it.
By the way in most circumstances you should try to avoid using floating point numbers if you can possibly avoid them. Remember software floating point can be rather slow and the floating point routines can make your programs much larger. So when working with small ram and rom sizes it is better to avoid floating point altogether when possible.
You may also be interested in this link for some ways around using floating point numbers.
Jim