1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "ts.h"
fp_t * ts_fill( fp_t *x, uint_t n, fp_t x0, fp_t x1 )
{
fp_t step = ( x1 - x0 ) / ( n - 1 );
if( x0 == 0.0 && x1 == 0.0 )
{
memset(x, 0, sizeof( fp_t ) * n );
}
else
{
for( uint_t i = 0; i < n; i++ )
{
x[i] = x0 + ( i * step );
}
}
return x;
}
void ts_print( fp_t *x, uint_t n )
{
fputc('[', stdout);
uint_t i;
for( i = 0; i < n - 1; i++ )
{
fprintf(stdout, "%f,", x[i]);
}
fprintf(stdout, "%f]", x[i]);
}
void ts_pretty_print( fp_t const * const *x, uint_t m, uint_t n )
{
if( m > 1 )
{
for( uint_t i = 0; i < n; i++ )
{
uint_t j = 0;
for( ; j < m; j++ )
{
fprintf( stdout, "%f ", x[i][j] );
}
fputs( "\n", stdout );
}
}
else
{
for( uint_t i = 0; i < n; i++ )
{
fprintf( stdout, "%f\n", x[0][i] );
}
}
}
fp_t _ts_square( fp_t x )
{
return x * x;
}
fp_t _ts_reciprocal( fp_t x )
{
return x != 0 ? 1.0 / x : INFINITY;
}
fp_t _ts_square_pyramidal_number( fp_t x )
{
return ( x * ( x + 1 ) * ( 2 * x + 1 ) ) / 6;
}
fp_t _ts_triangle_number( fp_t x )
{
return ( ( x ) * ( ( x ) + 1 ) ) * 0.5;
}
fp_t _ts_sum_to_covariance( fp_t sum_xy, fp_t sum_x, fp_t sum_y, uint_t k )
{
return ( sum_xy - ( sum_x * sum_y / k ) ) / k;
}
fp_t _ts_sum_to_variance( fp_t sum_x2, fp_t sum_x, uint_t k )
{
return _ts_sum_to_covariance( sum_x2, sum_x, sum_x, k );
}
uint_t _ts_circle_increment( uint_t i, uint_t k )
{
return ( i + 1 ) % k;
}
// ts_constant_t * ts_constant_init( uint_t n, ... )
// {
// va_list args;
// va_start( args, n );
// for( uint_t i = 0; i < n; i++ )
// {
// }
// }
|