Dollar gains as yen hits 40-year low