Avoid forcing the compiler to convert numbers between integer and floating-point internal representations. Conversions require several instructions, including some double-precision floating-point arithmetic. For example:
float array[10]; float x = 1.0; int i; for (i = 0; i< 9; i++) { /* No conversions needed */ array[i] = array[i]*x; x = x + 1.0; } for (i = 0; i< 9; i++) /* Multiple conversions needed */ array[i] = array[i]*i;
When you must use mixed-mode arithmetic, code the fixed-point and floating-point arithmetic in separate computations wherever possible.
Writing Optimized Code... Overview Variables Pointers Functions Function Arguments Expressions Critical Loops Arithmetic Conversions Inlined Components