Several "return static_cast<V>( ... )" added to avoid warning C4244 conversion from 'const double' to 'float'.
Not all tested by test_chi_squared usage :-( so a mistake might cause compile failures elsewhere?