12 #include "cl_LF_impl.h"
13 #include "cl_integer.h"
18 const cl_R cl_LF_I_mul (const cl_LF& x, const cl_I& y)
22 // If x=0.0, return x.
23 // If y is longer than x, convert y to a float and multiply.
24 // Else multiply the mantissa of x with the absolute value of y, then round.
25 if (eq(y,0)) { return 0; }
26 if (TheLfloat(x)->expo == 0) { return x; }
27 var cl_signean sign = -(cl_signean)minusp(y); // Vorzeichen von y
28 var cl_I abs_y = (sign==0 ? y : -y);
29 var uintL y_exp = integer_length(abs_y);
30 var uintC len = TheLfloat(x)->len;
31 #ifndef CL_LF_PEDANTIC
32 if (ceiling(y_exp,intDsize) > len)
33 return x * cl_I_to_LF(y,len);
35 // x länger als y, direkt multiplizieren.
37 var const uintD* y_MSDptr;
39 var const uintD* y_LSDptr;
40 I_to_NDS_nocopy(abs_y, y_MSDptr=,y_len=,y_LSDptr=,cl_false,); // NDS zu y bilden, y_len>0
41 if (mspref(y_MSDptr,0)==0) y_len--; // NUDS zu y bilden, y_len>0
43 var uintD* prodMSDptr;
45 UDS_UDS_mul_UDS(len,arrayLSDptr(TheLfloat(x)->data,len),
47 prodMSDptr=,prodlen=,);
48 // x fing mit 0 Nullbits an, y mit maximal intDsize-1 Nullbits,
49 // daher fängt das Produkt mit maximal intDsize Nullbits an.
51 if (mspref(prodMSDptr,0)==0) {
52 shiftcount = intDsize;
53 msshrink(prodMSDptr); prodlen--;
55 integerlengthD(mspref(prodMSDptr,0), shiftcount = intDsize -);
57 shiftleft_loop_lsp(prodMSDptr mspop (len+1),len+1,shiftcount,0);
59 // Produkt ist nun normalisiert: höchstes Bit =1.
60 // exponent := exponent(x) + intDsize*y_len - shiftcount
61 var uintL uexp = TheLfloat(x)->expo;
62 var uintL iexp = intDsize*y_len - shiftcount; // >= 0 !
64 if ((uexp < iexp) || (uexp > LF_exp_high))
65 cl_error_floating_point_overflow();
67 var uintD* midptr = prodMSDptr mspop len;
68 var uintC restlen = prodlen - len;
70 || ((sintD)mspref(midptr,0) >= 0) // nächstes Bit =0 -> abrunden
71 || ( ((mspref(midptr,0) & ((uintD)bit(intDsize-1)-1)) ==0) // Bit =1, weitere Bits >0 -> aufrunden
72 && !test_loop_msp(midptr mspop 1,restlen-1)
74 && ((lspref(midptr,0) & bit(0)) ==0)
80 { if ( inc_loop_lsp(midptr,len) )
81 // Übertrag durchs Aufrunden
82 { mspref(prodMSDptr,0) = bit(intDsize-1); // Mantisse := 10...0
83 if (++uexp == LF_exp_high+1) { cl_error_floating_point_overflow(); }
85 return encode_LFu(TheLfloat(x)->sign ^ sign, uexp, prodMSDptr, len);
87 // Bit complexity (N = max(length(x),length(y))): O(M(N)).