CHDK_DE Vorschauversion  Trunk Rev. 5830
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
gps_math.h-Dateireferenz
+ Dieser Graph zeigt, welche Datei direkt oder indirekt diese Datei enthält:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  t_regression_xy
 
struct  t_regression
 

Typdefinitionen

typedef char t_format_result [40]
 

Funktionen

int fac (int n)
 
double arctan (double x, int n)
 
double arctan2 (double y, double x)
 
double Round (double Zahl, int Stellen)
 
double ceil (double phi)
 
double floor (double phi)
 
const char * formatDouble (t_format_result result, double value, unsigned length, unsigned fracDigits)
 
void regressionInit (t_regression *rcb, int size, t_regression_xy buffer[])
 
void regressionReset (t_regression *rcb)
 
void regressionAdd (t_regression *rcb, double x, double y)
 
double regressionActual (t_regression *rcb)
 
double regressionForecast (t_regression *rcb, double x)
 
double regressionReverse (t_regression *rcb, double y)
 
double regressionChange (t_regression *rcb)
 
double regressionQuality (t_regression *rcb)
 
double sin (double phi)
 
double cos (double phi)
 

Dokumentation der benutzerdefinierten Typen

typedef char t_format_result[40]

Definiert in Zeile 35 der Datei gps_math.h.

Dokumentation der Funktionen

double arctan ( double  x,
int  n 
)

Definiert in Zeile 16 der Datei gps_math.c.

16  {
17 
18  double result=0.0;
19  int sign;
20  int i;
21 
22  if (abs(x) < 1 )
23  {
24  result = x;
25  sign = 0;
26  i = 3;
27 
28  do
29  {
30  sign ^= 1;
31  result += ((pow(x, i)/i) * ((sign) ? -1.0 : +1.0));
32  i+=2;
33  } while( (--n) ); // as long as member number is not zero
34  }
35 
36  if (abs(x) >= 1 )
37  {
38  if (x<-1) {result = 3.141592653589793* -0.5; }
39  if (x>=1) {result = 3.141592653589793*0.5; }
40  sign = 0;
41  i = 1;
42 
43  do
44  {
45  sign ^= 1;
46  result += ((1/(i*pow(x,i))) * ((sign) ? -1.0 : +1.0));
47  i+=2;
48  } while( (--n) ); // as long as member number is not zero
49 
50  }
51  return result;
52 }
double arctan2 ( double  y,
double  x 
)

Definiert in Zeile 54 der Datei gps_math.c.

54  {
55  double result;
56  result = 2.0 * arctan((y / (sqrt(x*x+y*y)+x)),30);
57  return result;
58 }
double ceil ( double  phi)

Definiert in Zeile 72 der Datei gps_math.c.

72  {
73  long long trunc = (double) (long long) arg;
74  return arg<=0 || trunc==arg ? trunc : trunc + 1.0;
75 }
double cos ( double  phi)

Definiert in Zeile 459 der Datei gps_math.c.

459  {
460  long periode = floor (phi / PIBY2 + 0.125);
461  double reduced = phi - PIBY2 * periode;
462  switch (periode&3) {
463  default:
464  return _cos (reduced);
465  case 1:
466  return -_sin (reduced);
467  case 2:
468  return -_cos (reduced);
469  case 3:
470  return _sin (reduced);
471  }
472 }
int fac ( int  n)

Definiert in Zeile 8 der Datei gps_math.c.

8  {
9 
10  int i;
11  int f=1;
12  for (i=2; i<=n; i++) f*=i;
13  return(f);
14 }
double floor ( double  phi)

Definiert in Zeile 64 der Datei gps_math.c.

64  {
65  long long trunc = (double) (long long) arg;
66  return arg>=0 || trunc==arg ? trunc : trunc - 1.0;
67 }
const char* formatDouble ( t_format_result  result,
double  value,
unsigned  length,
unsigned  fracDigits 
)

Definiert in Zeile 136 der Datei gps_math.c.

136  {
137 
138  char* sign = "";
139  quad expanded;
140  quad integer, fract;
141  unsigned integerDigits;
142  char* p;
143  unsigned shift = 0;
144  int origLength = length;
145 
146 #ifndef USE_LLI
147  char fractbuffer [20];
148 #endif
149 
150  /*-----------------------
151  * default buffer
152  *----------------------*/
153 
154  if (!result) result = staticBuffer;
155 
156  /*-----------------------
157  * sanity: length
158  *----------------------*/
159 
160  if (length ==0 ) length = sizeof(t_format_result)-1;
161  if (length < 3 ) length = 3;
162  if (length > sizeof(t_format_result)-1) length = sizeof(t_format_result)-1;
163 
164  /*-----------------------
165  * sanity: fract
166  *----------------------*/
167 
168  if (fractDigits > MAXDIGITS) fractDigits = MAXDIGITS;
169  if (fractDigits > length-3 ) fractDigits = length - 3;
170  integerDigits = length - fractDigits - 1;
171 
172  /*-----------------------
173  * abs
174  *----------------------*/
175 
176  if (value < 0) {
177  value = -value;
178  sign = "-";
179  }
180 
181  /*-----------------------
182  * scale
183  *----------------------*/
184 
185  value = value * (double) quadExpTable[fractDigits] + 0.5;
186 
187  while (value >= 9223372036854775807.0 && shift < fractDigits) {
188  shift++;
189  value *= 0.1;
190  }
191 
192  /*-----------------------
193  * general overflow?
194  *----------------------*/
195 
196  if (value >= 9223372036854775807.0) {
197  sprintf (result, "%*s", length, "***");
198  return result;
199  }
200 
201  /*-----------------------
202  * int+fract
203  *----------------------*/
204 
205  expanded = (quad) value;
206  integer = expanded / quadExpTable[fractDigits-shift];
207  fract = expanded % quadExpTable[fractDigits-shift] * quadExpTable[shift];
208 
209  /*-----------------------
210  * fixed overflow
211  *----------------------*/
212 
213  if (integer >= quadExpTable[min(*sign ? integerDigits-1 : integerDigits, MAXDIGITS)]) {
214  sprintf (result, "%*s", length, "***");
215  return result;
216  }
217 
218  /*-----------------------
219  * format
220  *----------------------*/
221 
222 #ifdef USE_LLI
223  if (!origLength) {
224  sprintf (result, "%s%lli.%0*lli", sign, integer, fractDigits, fract);
225  return result;
226  }
227  sprintf (result, "%*lli.%0*lli", integerDigits, integer, fractDigits, fract);
228 #else
229  if (fractDigits >= 10) {
230  sprintf (fractbuffer, "%0*li%09li", fractDigits-9,
231  (long) (fract/1000000000),
232  (long) (fract%1000000000));
233  } else {
234  sprintf (fractbuffer, "%0*li", fractDigits, (long) fract);
235  }
236 
237  if (integer >= 1000000000ll) {
238  if (!origLength) {
239  sprintf (result, "%s%li%09li.%s", sign,
240  (long) (integer/1000000000),
241  (long) (integer%1000000000),
242  fractbuffer);
243  return result;
244  }
245  sprintf (result, "%*li%09li.%s", integerDigits-9,
246  (long) (integer/1000000000),
247  (long) (integer%1000000000),
248  fractbuffer);
249  } else {
250  if (!origLength) {
251  sprintf (result, "%s%li.%s", sign, (long) integer, fractbuffer);
252  return result;
253  }
254  sprintf (result, "%*li.%s", integerDigits, (long) integer, fractbuffer);
255  }
256 #endif
257 
258  if (*sign) {
259  p = result;
260  while (p[1]==' ') p++;
261  p[0] = *sign;
262  }
263 
264  return result;
265 }
double regressionActual ( t_regression rcb)

Definiert in Zeile 364 der Datei gps_math.c.

364  {
365  regressionCompute (rcb);
366  return rcb->last_x * rcb->s + rcb->t;
367 }
void regressionAdd ( t_regression rcb,
double  x,
double  y 
)

Definiert in Zeile 304 der Datei gps_math.c.

304  {
305 
306  /* remove old value */
307 
308  if (rcb->n >= rcb->size) {
309  double old_x = rcb->values[rcb->index].x;
310  double old_y = rcb->values[rcb->index].y;
311  rcb->values[rcb->index].x = 0;
312  rcb->values[rcb->index].y = 0;
313  rcb->n -= 1;
314  rcb->sx -= old_x;
315  rcb->sy -= old_y;
316  rcb->sxx -= old_x*old_x;
317  rcb->sxy -= old_x*old_y;
318  rcb->valid = 0;
319  rcb->s = 0.0;
320  rcb->t = 0.0;
321  }
322 
323  if (rcb->n < rcb->size) {
324  rcb->n += 1;
325  rcb->sx += x;
326  rcb->sy += y;
327  rcb->sxx += x*x;
328  rcb->sxy += x*y;
329  rcb->valid = 0;
330  rcb->s = 0.0;
331  rcb->t = 0.0;
332  rcb->last_x = x;
333  rcb->values[rcb->index].x = x;
334  rcb->values[rcb->index].y = y;
335  rcb->index = (rcb->index+1) % rcb->size;
336  }
337 }
double regressionChange ( t_regression rcb)

Definiert in Zeile 391 der Datei gps_math.c.

391  {
392  regressionCompute (rcb);
393  return rcb->s;
394 }
double regressionForecast ( t_regression rcb,
double  x 
)

Definiert in Zeile 373 der Datei gps_math.c.

373  {
374  regressionCompute (rcb);
375  return x * rcb->s + rcb->t;
376 }
void regressionInit ( t_regression rcb,
int  size,
t_regression_xy  buffer[] 
)

Definiert in Zeile 272 der Datei gps_math.c.

272  {
273  rcb->size = size;
274  rcb->values = buffer;
275  regressionReset (rcb);
276 }
double regressionQuality ( t_regression rcb)

Definiert in Zeile 402 der Datei gps_math.c.

402  {
403  regressionCompute (rcb);
404  return rcb->valid==1 ? 1.0 : 0.0;
405 }
void regressionReset ( t_regression rcb)

Definiert in Zeile 282 der Datei gps_math.c.

282  {
283  int i;
284  rcb->n = 0;
285  rcb->sx = 0.0;
286  rcb->sy = 0.0;
287  rcb->sxx = 0.0;
288  rcb->sxy = 0.0;
289  rcb->last_x = 0.0;
290  rcb->valid = 0;
291  rcb->s = 0.0;
292  rcb->t = 0.0;
293  rcb->index = 0;
294  for (i=0; i<rcb->size; i++) {
295  rcb->values[i].x = 0;
296  rcb->values[i].y = 0;
297  }
298 }
double regressionReverse ( t_regression rcb,
double  y 
)

Definiert in Zeile 382 der Datei gps_math.c.

382  {
383  regressionCompute (rcb);
384  return rcb->s != 0.0 ? (y - rcb->t) / rcb->s : 1e9;
385 }
double Round ( double  Zahl,
int  Stellen 
)

Definiert in Zeile 104 der Datei gps_math.c.

104  {
105  return floor(number * doubleExpTable[places] + 0.5) / doubleExpTable[places];
106 }
double sin ( double  phi)

Definiert in Zeile 444 der Datei gps_math.c.

444  {
445  long periode = (long) floor (phi / PIBY2 + 0.5);
446  double reduced = phi - PIBY2 * periode;
447  switch (periode&3) {
448  default:
449  return _sin (reduced);
450  case 1:
451  return _cos (reduced);
452  case 2:
453  return -_sin (reduced);
454  case 3:
455  return -_cos (reduced);
456  }
457 }