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 a1,b1∈Z and a2,b2∈Z and a2≤0 and b2≤0 and
and
Both the numbers a0 and b0 are either integers or actual (finite length) decimals with this representation.
Now
Of course if a2+b2<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 a0b0 when represented as a string of digits.
Example: a0=5 and b0=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 integer or decimal form using (2).
No comments:
Post a Comment