How exactly is crit damage calculated?

The damage formula isn't posted on the wiki or in game via the codex

[B * (1 + AP/100)= iDmg] * [1 - (DR%)] * [1 - (ER%)] * RNG = fDmg]

where B = base dmg of the attack or spell
AP = attack power or spell power
DR% = dmg reduction after armor/ward/focus has been subtracted by armor/spell penetration or temptation
ER% = elemental resistance
RNG = some variable that makes it so not every outcome is the same

If i remember correctly, critical hits add a base +50 atk/spell power bonus.
That +50 AP bonus increases with crit effectiveness.
Crit effectiveness can be improved with higher Cunning.
The [Golden Carrot] bracelet can also boost crit effectiveness when HP is greater than 75%

I'm curious myself how it's all calculated...