Compile c code with float instead of double

前端 未结 2 755
醉酒成梦
醉酒成梦 2020-12-19 11:51

I have a lengthy numeric integration scheme written in C. I\'d like to test my algorithm in floating point precision. Is there a way to tell gcc to demote every occurrence o

2条回答
  •  失恋的感觉
    2020-12-19 12:19

    typedef double float; 
    

    Before any doubles that you want to replace should work, however be warned it may confuse some external libraries.

    In the future, the best approach is to define your own float type:

    #ifdef USE_FLOATS
        typedef float MyFloatType; 
    #else 
        typedef double MyFloatType;
    #endif
    

    Or use templates, which has the added benefit of allowing you to change the code at runtime to use one or the other.

提交回复
热议问题