Thread: float size

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    347

    float size

    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.

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    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;
    }

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    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.

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    Quote Originally Posted by Satya View Post
    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.
    Then check the documentation for both the controller, first, and the compiler. Check the websites for both, for technical specifications. One or both should give you the answers you need.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    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.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What microprocessor are you using?

    Jim

  7. #7
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    Quote Originally Posted by Satya View Post
    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.
    Then check the details of each compiler, in their documentation, and/or on the website, for that controller.

  8. #8
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    It is microchip.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Satya View Post
    It is microchip.
    Microchip makes literally dozens of series, and thousands of models of microcontroller. Which specific model are you using?
    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?

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    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

  11. #11
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    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?

  12. #12
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    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

  13. #13
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    OK got it.

  14. #14
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How i can convert int->float float->int safely?
    By Vanhapolle in forum C Programming
    Replies: 2
    Last Post: 11-04-2014, 08:22 PM
  2. Float and double size
    By _arjun in forum C Programming
    Replies: 7
    Last Post: 10-10-2011, 11:56 AM
  3. Finding Words in a array[size][size]
    By ^DJ_Link^ in forum C Programming
    Replies: 8
    Last Post: 03-08-2006, 03:51 PM
  4. Replies: 8
    Last Post: 07-08-2005, 09:12 AM
  5. Unresolved external 'convert(float, float)'
    By Ipsec Espah in forum C++ Programming
    Replies: 4
    Last Post: 05-21-2003, 10:08 AM

Tags for this Thread