Monday, 24 April 2017

arithmetic - How can you multiply decimal values without using a multiplication or division operator?



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,b1Z and a2,b2Z and a20 and b20 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

real analysis - How to find limhrightarrow0fracsin(ha)h

How to find limh0sin(ha)h without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...