What's the reverse of Math Power (**) in Ruby? -


I was wondering how to get the inversion of electricity in Ruby?

  2 ** 4 # = & gt; 16  

And then I want to reverse it, and I'm not sure which operator to use

  16 ?? 2 # = & gt; 4  

The inversion of exponentation is logarithmic.

If a b = c , then log a c = b .

You can find the logarithm in the module this logarithm base-E ( log ) or base-10 ( log 10 ). To obtain a logarithm for base-N, use the formula:

log n a = log x A <<> << X>

Where x is a value such as e log x or 10 . For your special case:

log 2 16 = log e 16 / log < All> E 2 = Math.log (16) / Math.log (2) = 4

Whether you consider the explanation because it expands your knowledge or is bad because you hate high school mathematics, you are dependent on: -)


Comments