In order to make sure the difference between two numbers is positive, we use
abs on their subtraction.
Is there an equivalent function that makes sure the ratio between two numbers is (say) larger than one?
I know I can:
fun(Φ) = Φ < 1 ? 1/Φ : Φ
But the same can be argued for
abs(Δ) = Δ < 0 ? -Δ : Δ
I’m just wondering if I missed something.
I have not encountered a standard name for this. But if the domain is positive, why not use logs and take the absolute difference, eg
Yea, you mean
exp(abs(log(r))), expensive though. OK, thanks.
No, I would just work with logarithms. This is pretty standard in statistics, as probabilities/likelihoods multiplied or divided run out of the range of
Float64 very quickly (usually a few hundred or at best thousand values), whereas
logs take you very far, and you just add/subtract.
If the ratios are trivial, you would of course be OK with something like
ifelse(r < 1, 1/r, r)
so it all depends on your application.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.