Microsoft has become only the second publicly traded company after Nvidia to surpass $4 trn (£3.03trn) in market valuation, after registering huge earnings.