Astrophysical fluid simulations of thermally ideal gases with non-constant adiabatic index: numerical implementation