Changeset 2394
 Timestamp:
 Feb 11, 2013, 4:27:49 PM (7 years ago)
 Location:
 trunk/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/lol/math/remez.h
r2183 r2394 57 57 printf("Step %i error: ", n); 58 58 newerror.print(m_decimals); 59 printf("\n"); 59 60 60 61 Step(); … … 77 78 } 78 79 79 T ChebyEval(T const &x)80 T EvalCheby(T const &x) 80 81 { 81 82 T ret = 0.0, xn = 1.0; … … 100 101 { 101 102 zeroes[i] = (T)(2 * i  ORDER) / (T)(ORDER + 1); 102 fxn[i] = Value(zeroes[i]);103 fxn[i] = EvalFunc(zeroes[i]); 103 104 } 104 105 … … 146 147 147 148 left.value = control[i]; 148 left.error = ChebyEval(left.value)  Value(left.value);149 left.error = EvalCheby(left.value)  EvalFunc(left.value); 149 150 right.value = control[i + 1]; 150 right.error = ChebyEval(right.value)  Value(right.value);151 right.error = EvalCheby(right.value)  EvalFunc(right.value); 151 152 152 153 static T limit = ldexp((T)1, 500); … … 155 156 { 156 157 mid.value = (left.value + right.value) / 2; 157 mid.error = ChebyEval(mid.value)  Value(mid.value);158 159 if ((left.error < zero && mid.error <zero)160  (left.error > zero && mid.error >zero))158 mid.error = EvalCheby(mid.value)  EvalFunc(mid.value); 159 160 if ((left.error <= zero && mid.error <= zero) 161  (left.error >= zero && mid.error >= zero)) 161 162 left = mid; 162 163 else … … 185 186 b = zeroes[i]; 186 187 187 T maxerror = 0, maxweight = 0;188 int best = 1;189 190 188 for (int round = 0; ; round++) 191 189 { 190 T maxerror = 0, maxweight = 0; 191 int best = 1; 192 192 193 T c = a, delta = (b  a) / 4; 193 194 for (int k = 0; k <= 4; k++) … … 195 196 if (round == 0  (k & 1)) 196 197 { 197 T error = ChebyEval(c)  Value(c); 198 T weight = Weight(c); 199 if (fabs(error * maxweight) >= fabs(maxerror * weight)) 198 T error = fabs(EvalCheby(c)  EvalFunc(c)); 199 T weight = fabs(Weight(c)); 200 /* if error/weight >= maxerror/maxweight */ 201 if (error * maxweight >= maxerror * weight) 200 202 { 201 203 maxerror = error; … … 218 220 b = a + delta * (best + 1); 219 221 a = a + delta * (best  1); 220 best = 2;221 222 break; 222 223 } … … 224 225 if (delta < m_epsilon) 225 226 { 226 T e = maxerror / maxweight;227 T e = fabs(maxerror / maxweight); 227 228 if (e > final) 228 229 final = e; … … 241 242 T fxn[ORDER + 2]; 242 243 for (int i = 0; i < ORDER + 2; i++) 243 fxn[i] = Value(control[i]);244 fxn[i] = EvalFunc(control[i]); 244 245 245 246 /* We build a matrix of Chebishev evaluations: row i contains the … … 335 336 } 336 337 337 printf("Polynomial estimate: \n");338 printf("Polynomial estimate: "); 338 339 for (int j = 0; j < ORDER + 1; j++) 339 340 { 340 341 if (j) 341 printf("+"); 342 printf("x**%i*", j); 342 printf(" + x**%i * ", j); 343 343 an[j].print(m_decimals); 344 344 } 345 printf("\n ");346 } 347 348 T Value(T const &x)345 printf("\n\n"); 346 } 347 348 T EvalFunc(T const &x) 349 349 { 350 350 return m_func(x * m_k2 + m_k1); 
trunk/src/math/real.cpp
r2322 r2394 1362 1362 for (int i = 0; i < BIGITS; i++) 1363 1363 std::printf(" %08x", m_mantissa[i]); 1364 std::printf("\n");1365 1364 } 1366 1365 … … 1371 1370 char *buf = new char[ndigits + 32 + 10]; 1372 1371 real::sprintf(buf, ndigits); 1373 std::printf("%s \n", buf);1372 std::printf("%s", buf); 1374 1373 delete[] buf; 1375 1374 } … … 1387 1386 if (!x) 1388 1387 { 1389 std::strcpy(str, "0.0 \n");1388 std::strcpy(str, "0.0"); 1390 1389 return; 1391 1390 } … … 1415 1414 /* Print exponent information */ 1416 1415 if (exponent) 1417 str += std::sprintf(str, "e%c%i", exponent > 0 ? '+' : '', exponent); 1416 str += std::sprintf(str, "e%c%i", 1417 exponent >= 0 ? '+' : '', lol::abs(exponent)); 1418 1418 1419 1419 *str++ = '\0';
Note: See TracChangeset
for help on using the changeset viewer.