I figured out a problem challenging me to write code to do this with integers, but I was wondering how I would have done it if it had been decimals and I couldn't figure it out.
Answer
Let
with $a_1, b_1 \in \Bbb Z$ and $a_2, b_2 \in \Bbb Z$ and $a_2 \le 0$ and $b_2 \le 0$ and
and
Both the numbers $a_0$ and $b_0$ are either integers or actual (finite length) decimals with this representation.
Now
Of course if $a_2 + b_2 \lt 0$ we have to make sure that the form is 'fixed up' to give a pure representation - you have to check/cancel at least one trailing zero (least significant digit) in the product $a_0 b_0$ when represented as a string of digits.
Example: $a_0 = 5$ and $b_0 = 0.2$:
The exponent is negative and the integer part has $0$ at the far right end. So you remove a zero and increment the exponent.
Since the exponent isn't negative there is nothing to check - the product is an integer and we are writing it in standard $\text{integer or decimal}$ form using $\text{(2)}$.
No comments:
Post a Comment