c++ - Set all floating point literals to floats MSVC++ -
i writing numeric code in c++ , want able swap between using double , float. have therefore added #define myflt can make either float or double needed. however, how deal various numeric literals. example
myflt somenumber = 1.2; myflt someothernumber = 1.5f;
gives compiler warnings first line when myflt float , second line when myflt double. know trivial example, there other cases have longer expresions literals in , floats can end being converted doubles result floats think costing me significant performance. how should deal this?
i things like
myflt somenumber = myflt(1.2); myflt someothernumber = myflt(1.5);
but quite tedious. i'm assuming in if compiler clever enough use float when needed (can confirm that?). better if there msvc++ compiler switch or #define tell compiler treat floating point literals floats instead of doubles. such switch exist?
even when wrap literals above code runs 50% slower when use float rather double. expecting performance boost through simd type operations, not penalty!
phil
what you'd want #define myfltconst(x) x##f
or #define myfltconst(x) x
depending on whether want f
suffix float
appended.
Comments
Post a Comment