Switching between float and double precision at compile time

前端 未结 3 1587
一向
一向 2021-01-14 15:27

Where should I look at if I want to switch between float and double precision at compile time. Its like, if user wants everything in float instead of double precision how I

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 16:06

    If it is OK to make the switch at compile time, a simple typedef would do:

    #ifdef USE_DOUBLES
    typedef double user_data_t;
    #else
    typedef float user_data_t;
    #endif
    

    Use user_data_t in your code, and set USE_DOUBLES if you want doubles at compile time:

    g++ -DUSE_DOUBLES=1 myprogram.cpp
    

提交回复
热议问题