The density of a gas is calculated using the ideal gas law and an equation of state calculation such as the one described in AGA Report No. 8.
There are broad general methodologies used to calculate the density of a liquid at specific conditions. In order to discuss a specific methodology, one must choose a liquid that holds sufficient interest to warrant a calculation specific to it. EOS 87.3 is a density calculation for seawater; API chapter 11 specifies calculations pertaining to oil, fuels and natural gas liquids.