The compiler treats 1/2 as integer division. Change one to a double to get floating division: 1.0/2