[Home]
[Contents]
[Chapter]
[Previous Algorithm]
[Next Algorithm]


Linear combination of two numbers


linear( a, ka, b, kb ) mp a, b; int ka, kb; /*** compute a*ka + b*kb --> a ***/ {int i, la, lb; la = length( a ); lb = length( b ); for (i=1; i<la; i++) a[i] *= ka; if ( sign(a)!=sign(b) ) kb = -kb; if ( lb>la ) { storelength( a, lb ); for (i=la; i<lb; i++) a[i] = 0; } for (i=1; i<lb; i++) a[i] += kb*b[i]; normalize( a ); };

C source (61.linear.c)



© Addison-Wesley Publishing Co. Inc.