Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

any significant difference

  • 07-03-2019 5:03pm
    #1
    Registered Users, Registered Users 2 Posts: 4,325 ✭✭✭


    Feel a bit silly asking in a new thread but just wondering if there is any significance in declaring a float like this:

    float whatever = 0.f;
    or
    float whatever = 0.0f;

    besides the dropped zero after the decimal is there any advantage to doing the first?


Comments

  • Registered Users, Registered Users 2 Posts: 10,902 ✭✭✭✭28064212


    Stating the language would help. In C#, the former is a syntax error. Assuming it's Java, you could just do this to test:
    float x = 0.F;
    float y = 0.0F;
    System.out.print(x == y);
    

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users, Registered Users 2 Posts: 4,325 ✭✭✭iLikeWaffles


    28064212 wrote: »
    Stating the language would help. In C#, the former is a syntax error. Assuming it's Java, you could just do this to test:
    float x = 0.F;
    float y = 0.0F;
    System.out.print(x == y);
    

    It's C++


  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭Anima


    There isn't a difference no.


  • Registered Users, Registered Users 2 Posts: 4,325 ✭✭✭iLikeWaffles


    I'm just thinking out loud here and a little busy porting code to set up a project.
    Just to followup. Lets say I have:
    #define pi   3.14159265358979323
    
    float 2pi = 0.00f;
    
    2pi = 2*pi;
    

    Would that make
    2pi == 6.28
    
    or
    2pi == 6.28318530717958646
    


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    You can just test these things for yourself!!

    Why would it round the float to two decimal places???


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 4,325 ✭✭✭iLikeWaffles


    You can just test these things for yourself!!

    Why would it round the float to two decimal places???

    As I said I'm a little busy and thinking out loud. Why have a forum if that's the case???


  • Moderators, Society & Culture Moderators Posts: 15,812 Mod ✭✭✭✭smacl


    I'm just thinking out loud here and a little busy porting code to set up a project.
    Just to followup. Lets say I have:
    #define pi   3.14159265358979323
    
    float 2pi = 0.00f;
    
    2pi = 2*pi;
    

    Would that make
    2pi == 6.28
    
    or
    2pi == 6.28318530717958646
    

    Neither.

    Edit:

    1) 2pi is not a legal variable name in C++
    2) If you were to use a legal variable name, e.g. TwoPi the value would be 6.28318548 which is limited by that fact that a float is only 4 bytes
    3) You should avoid == equality checks on doubles and floats in C++ for values other than zero, see https://stackoverflow.com/questions/18971533/c-comparison-of-two-double-values-not-working-properly Use an epsilon value or similar.


Advertisement