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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -