Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/23/05 17:22
Read: times


 
Msg Score: +1
 +1 Informative
#99922 - If actual fraction numbers
Responding to: ???'s previous message
If you mean actually fraction numbers that consists of integer numerator and denominator, define an integer pair, (numerator, denominator) as the data type.
Make the four operations procedure, addition, subtraction, multiplication and division as follows. Also, you'll need a reduction procedure using GCD (Greatest Common Divisor) by the Euclid reduction algorithm.

For instance,
Addition:
N1/D1 + N2/D2 = N3/D3
(N3,D3) = (N1*D2+N2*D1, D1*D2)
Then apply the reduction procedure.

Subtraction:
N1/D1 - N2/D2 = N3/D3
Invert the sign of N2 and call addition procedure.

Multiplication
N1/D1 * N2/D2 = N3/D3
(N3,D3) = (N1*N2, D1*D2)
Then apply the reduction procedure.

Division
N1/D1 / N2/D2 = N3/D3
Swap N2 and D2 and call multiplication procedure.

Tsuneo

List of 16 messages in thread
TopicAuthorDate
Mathematics of Fractional # in Intel ass            01/01/70 00:00      
   Search            01/01/70 00:00      
      Actual task            01/01/70 00:00      
         Lookup table?            01/01/70 00:00      
         Scale it            01/01/70 00:00      
   echo...........            01/01/70 00:00      
   sounds like fun, but it will take you ma            01/01/70 00:00      
      Using C            01/01/70 00:00      
         C            01/01/70 00:00      
            Space occupied            01/01/70 00:00      
               That old chestnut!            01/01/70 00:00      
                  Example            01/01/70 00:00      
               Does it really matter, anyhow?            01/01/70 00:00      
                  why assembler            01/01/70 00:00      
   If actual fraction numbers            01/01/70 00:00      
   And decimal number,            01/01/70 00:00      

Back to Subject List