You are looking for optimization in the wrong place. Compilers will do as many computations as possible at compile time, if you enable optimizing. Any mathematical expression consisting entirely of constants probably will fall into this category. Here's an example of 2 programs and what they look like after compiling on gcc with the following flags:
-03 (optimization)
-S (to prevent assembling; thus stopping at assembler code. So we can compare output.)
test21_1.c
Code:
#include <stdio.h>
int main(void) {
float a_float;
float another_float = 2.3f;
a_float = another_float*2/3;
return 0;
}
test21_2.c
Code:
#include <stdio.h>
int main(void) {
float a_float;
float another_float = 2.3f;
a_float = another_float*222/111/(18/6);
return 0;
}
OUTPUT:
test21_1
Code:
.file "test21_1.c"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
xorl %eax, %eax
pushl %ebp
movl %esp, %ebp
pushl %ecx
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (GNU) 4.1.1 20060525 (Red Hat 4.1.1-1)"
.section .note.GNU-stack,"",@progbits
test21_2
Code:
.file "test21_2.c"
.text
.p2align 4,,15
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
xorl %eax, %eax
pushl %ebp
movl %esp, %ebp
pushl %ecx
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.size main, .-main
.ident "GCC: (GNU) 4.1.1 20060525 (Red Hat 4.1.1-1)"
.section .note.GNU-stack,"",@progbits
The output is the same in each case (obviously). Basically, make sure you read the manual for your compiler and at least enable basic optimizing. There is also a few options which control floating point mathematics. You can speed it up, if you enable those options, which might rely on certain requirements (see manual). Lastly, you can tune the output for a specific processor group. All of these things are probably going to make hundred times more difference in speed than writing 2/3 or 4/6 or 0.6667 or (((0.6667))).