~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/math/vector/vec_get.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)Vector (1 dimensional array) component reading
  2  */
  3 
  4 #include <stdio.h>
  5 #include <tina/sys.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 
  9 static Complex zero = {Complex_id, 0.0, 0.0};
 10 
 11 void   *vector_getp(Vector * v, int i)
 12 {
 13     void   *vi;
 14 
 15     if (v == NULL || v->vtype != ptr_v)
 16         return (NULL);
 17     if (i < 0 || i >= v->n)
 18         return (NULL);
 19     VECTOR_GETP(v, i, vi);
 20     return (vi);
 21 }
 22 
 23 int     vector_get(Vector * v, int i)
 24 {
 25     double    vi;
 26 
 27     if (v == NULL || v->vtype == ptr_v)
 28         return (0);
 29     if (i < 0 || i >= v->n)
 30         return (0);
 31     VECTOR_GET(v, i, vi);
 32     return ((int)vi);
 33 }
 34 
 35 double  vector_getf(Vector * v, int i)
 36 {
 37     double  vi;
 38 
 39     if (v == NULL || v->vtype == ptr_v)
 40         return (0.0);
 41     if (i < 0 || i >= v->n)
 42         return (0.0);
 43     VECTOR_GET(v, i, vi);
 44     return (vi);
 45 }
 46 
 47 Complex vector_getz(Vector * v, int i)
 48 {
 49     Complex vi = {Complex_id};
 50 
 51     if (v == NULL || v->vtype == ptr_v)
 52         return (zero);
 53     if (i < 0 || i >= v->n)
 54         return (zero);
 55     VECTOR_GETZ(v, i, vi);
 56     return (vi);
 57 }
 58 
 59 double  vector_interpf(Vector * v, double x)
 60 {
 61     int     xi;
 62     double  x1, x2;
 63     double  vi, v1, v2;
 64 
 65     if (v == NULL || v->vtype == ptr_v)
 66         return (0);
 67     if (x < 0 || x > v->n)
 68         return (0.0);
 69 
 70     if (x < v->n)
 71         xi = (int)x;
 72     else
 73         xi = v->n;
 74 
 75     x1 = x - xi;
 76     x2 = 1.0 - x1;
 77     VECTOR_GET(v, xi, v1);
 78     VECTOR_GET(v, xi + 1, v2);
 79     vi = x2 * v1 + x1 * v2;
 80     return (vi);
 81 }
 82 
 83 Complex vector_interpz(Vector * v, double x)
 84 {
 85     int     xi;
 86     double  x1, x2;
 87     Complex vi = {Complex_id};
 88     Complex v1 = {Complex_id};
 89     Complex v2 = {Complex_id};
 90 
 91     if (v == NULL || v->vtype == ptr_v)
 92         return (zero);
 93     if (x < 0 || x > v->n)
 94         return (zero);
 95 
 96     if (x < v->n)
 97         xi = (int)x;
 98     else
 99         xi = v->n;
100 
101     x1 = x - xi;
102     x2 = 1.0 - x1;
103     VECTOR_GETZ(v, xi, v1);
104     VECTOR_GETZ(v, xi + 1, v2);
105     vi.x = x2 * v1.x + x1 * v2.x;
106     vi.y = x2 * v1.y + x1 * v2.y;
107     return (vi);
108 }
109 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.