Representing big numbers in source code for readability?

后端 未结 5 2102
难免孤独
难免孤独 2020-11-27 23:23

Is there a more human-readable way for representing big numbers in the source code of an application written in C++ or C?

let\'s for example take the number 2,

5条回答
  •  清歌不尽
    2020-11-28 00:05

    You could use a preprocessor macro

      #define BILLION (1000*1000*1000)
    

    then code e.g. (4*BILLION) ; if you care about large power of two just ust 1<<30

    PS Notice that 1e6 is a double literal (same as 1.0e6)

    And you could also:

    1. patch the GCC lexer to accept 1_234_567 notation for number literals and publish that patch for conformance with GPLv3 and free software spirit.
      probably in file libpp/lex.c and/or gcc/c-family/c-lex.c and/or gcc/cpp/lex.c of future GCC 4.8, i.e. current trunk.
    2. lobby the C & C++ standardization groups to get that accepted in future C or C++ standards.

提交回复
热议问题