1
$\begingroup$

I'm given this set of floating point numbers:

enter image description here

And I'm given the function:

enter image description here

I'm then asked to find the value of f for:

enter image description here

enter image description here

So I've done this:

enter image description here

Now my guess is that I need to convert the exact value (1.666...) into a representable value according to the floating point numbers I'm allowed to work with. Rounding it up I get:

enter image description here

Now again I guess I need to round 1.000167 to 1.00 (maybe I should have already rounded 0.000167 to 0.00 ?):

enter image description here

f(x2) is 0 as well. And to be honest I doubt that the exercise required me to calculate 2 values only to find out they're both 0. Also because it then asks me to find the relative error in both cases and explain the differences. It also asks me to find an alternate form to avoid loss of significance but that's not what I'm posting this question for.

What I need to know is: is the function really 0 in both cases? Am I right when rounding the partial operations? Or should I maybe round at the end?

$\endgroup$
2
  • 1
    $\begingroup$ What does "the function: $f(x)=...$" mean here? Are you allowed to rearrange the formula in a way that is mathematically equivalent but better for FP computations? $\endgroup$ Dec 19, 2019 at 23:17
  • $\begingroup$ @kimchilover As pointed out in the question: "...It also asks me to find an alternate form to avoid loss of significance but that's not what I'm posting this question for...." I know what the alternate form is and I know it's way more precise. But that's not what I'm asking. What I really was looking for has been explained in the accepted answer. $\endgroup$
    – zcb
    Dec 20, 2019 at 14:52

1 Answer 1

0
$\begingroup$

The usual rule is that you should round at all stages of the computation. This is supposed to represent how computers do floating point math but using a granularity of numbers that reduces the labor and makes the problem more obvious. Computers round at every stage because they have to store the value in memory, which they do in the defined floating point format. In that case $1+\frac 1x=1$ for both of your inputs and I agree with you it is strange that you were asked to do the computation twice when both give $0$. If I were writing the problem the first input would be $2$ or something like that where the computation comes out reasonably well. The second input would be something large like you got, showing that you get $0$.

You should not have already rounded $0.000166667$ to $0.00$ because you can represent it as $1.67\cdot 10^{-4}$. That is how floating point works. It only disappears when you add it to $1$.

As a nit, I would show all the numbers with two decimal places, so your $6\cdot 10^3$s should be $6.00\cdot 10^3$s. I think that is in the spirit of the problem.

$\endgroup$
2
  • $\begingroup$ Can the computer directly sum 1.67*10^-4 and 1? Shouldn't it represent them with the same base (eg. 10^0) and only then add the mantissas? And if so, how can it represent 0.000166667 when it has only 3 digits for mantissa (in this example)? $\endgroup$
    – zcb
    Dec 20, 2019 at 15:08
  • $\begingroup$ Yes, it needs to represent them with the same exponent to add. You can represent $1.67\cdot 10^{-4}$ in your floating point system, so you should not round it to zero. You might do something different with it later on. I could have a program that then multiplies it by $6.00\cdot 10^2$ and gets $1.02\cdot 10^{-1},$ for example. When you add it to $1.00 \cdot 10^0$ you get $1.00\cdot 10^0$ again because the extra rounds off to zero. $\endgroup$ Dec 20, 2019 at 15:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.