1 #ifndef vm_vmath_h_INCLUDED
2 #define vm_vmath_h_INCLUDED
77 template <
class T_fp,
int N_len>
82 enum ENelts_ { ENelts = N_len };
107 inline static void copy( T_fp v[], T_fp
const cv[] );
120 inline static void set( T_fp v[], T_fp r );
133 inline static void add_eq( T_fp v[], T_fp
const cv[] );
141 inline static void sub_eq( T_fp v[], T_fp
const cv[] );
149 inline static void mul_eq( T_fp v[], T_fp
const cv[] );
157 inline static void div_eq( T_fp v[], T_fp
const cv[] );
165 inline static void add_eq( T_fp v[], T_fp r );
173 inline static void sub_eq( T_fp v[], T_fp r );
181 inline static void mul_eq( T_fp v[], T_fp r );
189 inline static void div_eq( T_fp v[], T_fp r );
196 inline static void negate( T_fp v[] );
210 inline static void add( T_fp v[], T_fp
const cv1[], T_fp
const cv2[] );
219 inline static void sub( T_fp v[], T_fp
const cv1[], T_fp
const cv2[] );
228 inline static void mul( T_fp v[], T_fp
const cv1[], T_fp
const cv2[] );
237 inline static void div( T_fp v[], T_fp
const cv1[], T_fp
const cv2[] );
246 inline static void add( T_fp v[], T_fp
const cv[], T_fp r );
255 inline static void sub( T_fp v[], T_fp
const cv[], T_fp r );
264 inline static void mul( T_fp v[], T_fp
const cv[], T_fp r );
273 inline static void div( T_fp v[], T_fp
const cv[], T_fp r );
282 inline static void add( T_fp v[], T_fp r, T_fp
const cv[] );
291 inline static void sub( T_fp v[], T_fp r, T_fp
const cv[] );
300 inline static void mul( T_fp v[], T_fp r, T_fp
const cv[] );
309 inline static void div( T_fp v[], T_fp r, T_fp
const cv[] );
329 inline static void lincomb( T_fp res[],
330 T_fp c1, T_fp
const v1[],
331 T_fp c2, T_fp
const v2[] );
348 inline static std::ostream&
349 print_on( std::ostream& os, T_fp
const v[],
int by,
350 char const prefix[] =
"",
char const postfix[] =
"" );
362 cprint_on( FILE* of, T_fp
const v[],
int by,
363 char const prefix[] =
"",
char const postfix[] =
"" );
383 template <
class T_fp,
int N_len>
385 copy( T_fp v[], T_fp
const cv[] )
386 { memcpy( v, cv, N_len *
sizeof(T_fp) ); }
391 template <
class T_fp,
int N_len>
394 {
int n = N_len+1;
while ( --n ) { *v++ = r; } }
399 #define _tpl_Op_EQ_(_OPNAM_,_OPEQ_) \
400 template <class T_fp, int N_len> \
401 inline void vm_VMath<T_fp,N_len>::_OPNAM_( T_fp v[], T_fp const cv[] ) \
402 { int n = N_len+1; while ( --n ) { *v++ _OPEQ_ *cv++; } } \
403 template <class T_fp, int N_len> \
404 inline void vm_VMath<T_fp,N_len>::_OPNAM_( T_fp v[], T_fp r ) \
405 { int n = N_len+1; while ( --n ) { *v++ _OPEQ_ r; } }
406 _tpl_Op_EQ_(add_eq,+=)
407 _tpl_Op_EQ_(sub_eq,-=)
408 _tpl_Op_EQ_(mul_eq,*=)
409 _tpl_Op_EQ_(div_eq,/=)
412 template <
class T_fp,
int N_len>
415 {
int n = N_len+1;
while ( --n ) { *v = - *v; ++v; } }
419 #define _tpl_BinOp_(_OPNAM_,_OP_) \
420 template <class T_fp, int N_len> \
421 inline void vm_VMath<T_fp,N_len>::_OPNAM_( T_fp v[], \
422 T_fp const cv1[], T_fp const cv2[] ) \
423 { int n = N_len+1; while ( --n ) { *v++ = *cv1++ _OP_ *cv2++; } } \
424 template <class T_fp, int N_len> \
425 inline void vm_VMath<T_fp,N_len>::_OPNAM_( T_fp v[], T_fp const cv[], T_fp r ) \
426 { int n = N_len+1; while ( --n ) { *v++ = *cv++ _OP_ r; } } \
427 template <class T_fp, int N_len> \
428 inline void vm_VMath<T_fp,N_len>::_OPNAM_( T_fp v[], T_fp r, T_fp const cv[] ) \
429 { int n = N_len+1; while ( --n ) { *v++ = r _OP_ *cv++; } }
439 template <
class T_fp,
int N_len>
442 T_fp c1, T_fp
const v1[],
443 T_fp c2, T_fp
const v2[] )
444 {
int n = N_len+1;
while ( --n ) { *res++ = c1 * *v1++ + c2 * *v2++; } }
449 template <
class T_fp,
int N_len>
451 print_on( std::ostream& os, T_fp
const v[],
int by,
452 char const prefix[],
char const postfix[] )
454 if ( std::strlen(prefix) ) { os << prefix; }
465 if ( std::strlen(postfix) ) { os << postfix; }
469 template <
class T_fp,
int N_len>
472 char const prefix[],
char const postfix[] )
474 if ( std::strlen(prefix) ) { std::fprintf(of,
"%s", prefix); }
481 fprintf(of,
"%.18e ", *v++);
483 fprintf(of,
"%.18e\n", *v++);
485 if ( std::strlen(postfix) ) { std::fprintf(of,
"%s", postfix); }