1
$\begingroup$

I am facing a problem with natural logarithmic function in fixed-point notation.

Let's say

$$x = 0.54, \qquad\text{then}\qquad \ln(x) = -0.616186, \qquad\text{a negative number} \tag{1}$$

Then in fixed-point notation, the value of $x$ is calculated by (assuming $x$ is $\rm Q8.24$ format)

temp_var = 0.54 * 16777216 = 9059696 (fixed point value in Q8.24 format)

So,

$$x = \ln(\textrm{temp_var}) = 16.01\qquad\text{since}\qquad 2^{24} = 16777216$$

And the float (true / unscaled form) value corrosponds to

$$16.01 / 16777216 = 9.54e-7\qquad\text{a positive value}\tag{2}$$

As we can see, both $(1)$ and $(2)$ are different in both magnitude and sign.

So, I just want to know how to solve these kinds of problems at a fixed point?

$\endgroup$
14
  • 2
    $\begingroup$ The log rule is ln(a*b)= ln(a) + ln(b). And x = ln(0.54 * 16777216) =16.01 not ln(16.01) $\endgroup$ – Irreducible Jul 10 '20 at 6:27
  • $\begingroup$ @Irreducible..I have corrected the mistake $\endgroup$ – rkc Jul 10 '20 at 9:17
  • $\begingroup$ @rkc um, why are you dividing your logarithm value... that's not how logarithms work. $\endgroup$ – Marcus Müller Jul 10 '20 at 9:32
  • $\begingroup$ @MarcusMüller Hi, I am dividing by 16777216, just to get the true and original value of x (unscaled form). The fixed-point representation of x is 16 (8.24 format). So, the true value corresponds to (float)16 / 16777216, right? $\endgroup$ – rkc Jul 10 '20 at 10:07
  • 1
    $\begingroup$ please read the first comment again, the logarithmus rule is: log(a*b) = log(a) + log(b), that is why your division makes no sense, that is not how logarithmus works. $\endgroup$ – Irreducible Jul 13 '20 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.