void *btv_insert(void *key, node *base, size_t *num, size_t width, FCMP fcmp) { node *p, *s; p = base; s = base->left; while (s != NULL) { p = s; if (fcmp(key, s+1) < 0) s = s->left; else s = s->right; } if ((s = (node*)malloc(sizeof(node) + width)) == NULL) return NULL; memcpy(s+1, key, width); s->left = NULL; s->right = NULL; if (fcmp(key, p+1) < 0 || p == base) p->left = s; else p->right = s; (*num)++; return s; }
void *binse(const void *key, const void *base, size_t nelem, size_t width, int(*fcmp)(const void *, const void *)) { char *low,*high,*mid; low = (char *)base; high = (char *)base + (nelem - 1) * width; while(low <= high) { nelem = (high - low) / width + 1; printf("nelem is %d",nelem); mid = low + (nelem - 1 ) / 2 * width ; //important // printf("low is %d mid is %d\n",*low,*(int *)mid); if (fcmp((char *)key,mid) < 0) { high = mid - width; //important } else if (fcmp((char *)key,mid) > 0) { low = mid + width; //important // printf("low is %d, high is %d\n",*(int *)low,*(int *)high); } else return mid; } return NULL; }
//exp(-U) should be the likelihood for this determination. // -- probably needs conversion...? double PreCalDet::U(double theta) { if (distlen <= 0) { return cc->U(med, vr, theta); } //in bounds of passed dist... if (fcmp(theta, minage) > -1 && fcmp(theta, maxage) < 1) { int min = 0; int max = distlen-1; int mid = (min + max)/2; double interp = 0; //so! theta is a year, and ydist is a list of years. // we want year[mid] <= theta AND year[mid+1] > theta while (!( (fcmp(ydist[mid], theta) <= 0) && (fcmp(ydist[mid+1], theta) > 0) )) { if (fcmp(theta, ydist[mid]) > 0) min = mid + 1; else max = mid - 1; mid = (min + max)/2; } //linear interpolation interp = pdist[mid] + (theta-ydist[mid])*(pdist[mid+1]-pdist[mid])/(ydist[mid+1]-ydist[mid]); return -log(interp); } else { //a probability of 0 is returned from the likelihood function as +infinity //I'm just using a big (for this application) number here. return 500; } }
EXTERN int val_compare( value a, value b ) { char tmp_buf[32]; switch( C(val_type(a),val_type(b)) ) { case C(VAL_INT,VAL_INT): return icmp(val_int(a),val_int(b)); case C(VAL_INT32,VAL_INT): return icmp(val_int32(a),val_int(b)); case C(VAL_INT,VAL_INT32): return icmp(val_int(a),val_int32(b)); case C(VAL_INT32,VAL_INT32): return icmp(val_int32(a),val_int32(b)); case C(VAL_INT,VAL_FLOAT): return fcmp(val_int(a),val_float(b)); case C(VAL_INT32,VAL_FLOAT): return fcmp(val_int32(a),val_float(b)); case C(VAL_INT,VAL_STRING): return scmp(tmp_buf,sprintf(tmp_buf,"%d",val_int(a)),val_string(b),val_strlen(b)); case C(VAL_INT32,VAL_STRING): return scmp(tmp_buf,sprintf(tmp_buf,"%d",val_int32(a)),val_string(b),val_strlen(b)); case C(VAL_FLOAT,VAL_INT): return fcmp(val_float(a),val_int(b)); case C(VAL_FLOAT,VAL_INT32): return fcmp(val_float(a),val_int32(b)); case C(VAL_FLOAT,VAL_FLOAT): return fcmp(val_float(a),val_float(b)); case C(VAL_FLOAT,VAL_STRING): return scmp(tmp_buf,sprintf(tmp_buf,FLOAT_FMT,val_float(a)),val_string(b),val_strlen(b)); case C(VAL_STRING,VAL_INT): return scmp(val_string(a),val_strlen(a),tmp_buf,sprintf(tmp_buf,"%d",val_int(b))); case C(VAL_STRING,VAL_INT32): return scmp(val_string(a),val_strlen(a),tmp_buf,sprintf(tmp_buf,"%d",val_int32(b))); case C(VAL_STRING,VAL_FLOAT): return scmp(val_string(a),val_strlen(a),tmp_buf,sprintf(tmp_buf,FLOAT_FMT,val_float(b))); case C(VAL_STRING,VAL_BOOL): return scmp(val_string(a),val_strlen(a),val_bool(b)?"true":"false",val_bool(b)?4:5); case C(VAL_BOOL,VAL_STRING): return scmp(val_bool(a)?"true":"false",val_bool(a)?4:5,val_string(b),val_strlen(b)); case C(VAL_STRING,VAL_STRING): return scmp(val_string(a),val_strlen(a),val_string(b),val_strlen(b)); case C(VAL_BOOL,VAL_BOOL): return (a == b) ? 0 : (val_bool(a) ? 1 : -1); case C(VAL_OBJECT,VAL_OBJECT): if( a == b ) return 0; { value tmp = val_field(a,id_compare); if( tmp == val_null ) return invalid_comparison; a = val_callEx(a,tmp,&b,1,NULL); } if( val_is_int(a) ) return val_int(a); return invalid_comparison; default: if( a == b ) return 0; return invalid_comparison; } }
bool quat_cmp (const QUAT * a, const QUAT * b) { return fcmp (a->w, b->w) && fcmp (a->x, b->x) && fcmp (a->y, b->y) && fcmp (a->z, b->z); }
float position_getRollR (const POSITION p) { if (p == NULL) return 0.0; if (p->dirty == true) WARNING ("Whoops getting outdated axes (roll)"); if (fcmp (p->view.up.x, 1.0) || fcmp (p->view.up.x, -1.0)) return 0.0; return atan2 (p->view.up.z, p->view.up.x); }
/*[0,pi/4)に簡約*/ uint32_t fsin(uint32_t f){ if(fcmp(f,0) == 0) return fneg(fsin(f - (1 << 31))); if(fcmp(f,0x40c90fda) == 2) return fsin(fadd(f,0xc0c90fda)); if(fcmp(f,MYPI) == 0){ if(fcmp(f,MYPI2) == 0){ if(fcmp(f,MYPI4) == 0) return kernel_sin(f); else return kernel_cos(fadd(MYPI2,fneg(f))); }else{ if(fcmp(f,fadd(MYPI4,MYPI2)) == 0) kernel_cos(fadd(f,fneg(MYPI2))); else kernel_sin(fadd(MYPI,fneg(f))); } }else{ f = fadd(f,fneg(MYPI)); if(fcmp(f,MYPI2) == 0){ if(fcmp(f,MYPI4) == 0) return fneg(kernel_sin(f)); else return fneg(kernel_cos(fadd(MYPI2,fneg(f)))); }else{ if(fcmp(f,fadd(MYPI4,MYPI2)) == 0) fneg(kernel_cos(fadd(f,fneg(MYPI2)))); else fneg(kernel_sin(fadd(MYPI,fneg(f)))); } } }
float position_getPitchR (const POSITION p) { if (p == NULL) return 0.0; if (p->dirty == true) WARNING ("Whoops getting outdated axes (pitch)"); if (fcmp (p->view.up.x, 1.0)) return M_PI_2; else if (fcmp (p->view.up.x, -1.0)) return -M_PI_2; return asin (p->view.up.x); }
void *btv_search(void *key, node *base, size_t *num, size_t width, FCMP fcmp) { node *s; s = base->left; while (fcmp(key, s+1) != 0 && s != NULL) { if (fcmp(key, s+1) < 0) s = s->left; else s = s->right; } if (s == NULL) return NULL; else return s+1; }
void addToTree(tleaf*ptree,void*pdata,int(*fcmp)(void*,void*)) { if (ptree->pdata==NULL) ptree->pdata=pdata; else { if(!fcmp(ptree->pdata,pdata)) { if (ptree->pr==NULL) { ptree->pr=malloc(sizeof(tleaf)); *(ptree->pr)=leafempty; } addToTree(ptree->pr,pdata,fcmp); } else { if (ptree->pl==NULL) { ptree->pl=malloc(sizeof(tleaf)); *(ptree->pl)=leafempty; } addToTree(ptree->pl,pdata,fcmp); } } }
void *addItemToList(tList *pList, void *pItem, int(*fcmp)(void *pItList, void *pItNew)) { if(pItem) { if(pList->phead) { pList->pcurr=pList->phead; while(pList->pcurr) { if(fcmp(pList->pcurr->pdata, pItem) > 0) { InsertBefore(pList, pItem); break; } else if(pList->pcurr == pList->ptail) { InsertTail(pList, pItem); break; } GetNext(pList); } } else InsertHead(pList, pItem); } return 0; }
void Arbol_binario<T>::insertar(const T& dato, int (* fcmp)(const T&, const T&)) { /* Si la raíz no tiene dato, guárdalo. */ if (this->dato==nullptr) { this->dato=new T {dato}; return; } /* Si el dato es menor que el de esta hoja... */ if ((fcmp(*(this->dato),dato))>0) { /* y no hay hoja izquierda, crea una con el dato. */ if (hoja_izq==nullptr) hoja_izq=new Arbol_binario {dato}; /* Sino, inserta en la hoja izquierda. */ else hoja_izq->insertar(dato,fcmp); return; } /* Si el dato es mayor que el de esta hoja... */ else { /* y no hay hoja derecha, crea una con el dato. */ if (hoja_der==nullptr) hoja_der=new Arbol_binario {dato}; /* Sino, vuelve a intentar con la hoja derecha. */ else hoja_der->insertar(dato,fcmp); return; } }
void *btv_delete1(void *key, node *base, size_t *num, size_t width, FCMP fcmp) { node *parent, *son, *del, *nexth; parent = base; del = base->left; while (fcmp(key, del+1) != 0 && del != NULL) { parent = del; if (fcmp(key, del+1) < 0) del = del->left; else del = del->right; } if (del == NULL) return NULL; if (del->left == NULL && del->right == NULL) son = NULL; else if (del->left != NULL && del->right != NULL) { nexth = del->right; if (nexth->left != NULL) { while (nexth->left->left != NULL) nexth = nexth->left; son = nexth->left; nexth->left = son->right; son->left = del->left; son->right = del->right; } else { son = nexth; son->left = del->left; } } else { if (del->left != NULL) son = del->left; else son = del->right; } if (fcmp(key, parent+1) < 0 || parent == base) parent->left = son; else parent->right = son; free(del); (*num)--; return parent; }
bool initSimplex() { nCnt=bCnt=0; for(int i=1; i<=n; i++) N[++nCnt]=i; for(int i=1; i<=m; i++) B[++bCnt]=i+n,A[i][n+i]=1.0; R=bCnt,C=bCnt+nCnt; double minV=INF; int p=-1; for(int i=1; i<=m; i++) if(fcmp(minV,b[i])==1) minV=b[i],p=i; if(fcmp(minV,0.0)>=0) return true; N[++nCnt]=n+m+1; R++,C++; for(int i=0; i<=C; i++) A[R][i]=0.0; for(int i=1; i<=R; i++) A[i][n+m+1]=-1.0; Pivot(p,n+m+1); if(!Process(A[R])) return false; if(fcmp(b[R],0.0)!=0) return false; p=-1; for(int i=1; i<=bCnt&&p==-1; i++) if(B[i]==n+m+1) p=i; if(p!=-1) { for(int i=1; i<=nCnt; i++) { if(fcmp(A[p][N[i]],0.0)!=0) { Pivot(p,N[i]); break; } } } bool f=false; for(int i=1; i<=nCnt; i++) { if(N[i]==n+m+1) f=true; if(f&&i+1<=nCnt) N[i]=N[i+1]; } nCnt--; R--,C--; return true; }
/*encuentra el maximo ai en valor abs de una vector y devuelve su indice*/ void indice_max_vector(double *v, int n, int &indice, int *phi) { indice =0; for(int i=0; i<n; i++) /// A < B indice = ( (fcmp( phi[indice]*fabs(v[indice]), phi[i]*fabs(v[i])) == -1) ? i : indice); // return indice; }
bool IB_CORE_EXPORT operator== ( const ibMtx4& lhs, const ibMtx4& rhs ) { for (u32 n = 0; n < 16; ++n) { if (!fcmp(lhs.data.f[n], rhs.data.f[n])) return false; } return true; }
/*Returns 1 if v = u, component to component*/ int vector_cmp(double *v, double *u, int n) { int i = 0; while ((fcmp( v[i], u[i]) == 0) && (i<n)) i++; if (i==n) return 1; else return 0; }
void *hsc_search(void *key, node *base, size_t *num, size_t width, FCMP fcmp, HASH hash) { node *t; t = base[hash(key)].next; while (t != NULL && fcmp(key, t+1) != 0) t = t->next; if (t == NULL) return NULL; else return t+1; }
bool matrix4x4::isEqual( const matrix4x4 &other ) const { for( int x=0; x<16; x++ ) { if( !fcmp(_data[x],other._data[x]) ) { return FALSE; } } return TRUE; }
static int WINAPI fcmp2(const void *first,const void *second,void *) { return( fcmp( ((const NMNames *)first)->Flags, ((const NMNames *)second)->Flags, ((const NMNames *)first)->Text, ((const NMNames *)second)->Text ) ); }
T Arbol_binario<T>::extraer(const T& llave, int (* fcmp)(const T&, const T&)) { /* Si la raíz no tiene dato, no hay nada que extraer. */ if (dato==nullptr) throw std::range_error {"extraer() de Arbol_binario::vacio()==true"}; int dif; /* Si se encontró el dato... */ if (!(dif = fcmp(*dato,llave))) { T dato {std::move(*(this->dato))}; delete this->dato; this->dato=nullptr; /* y hay hoja derecha... */ if (hoja_der!=nullptr) { /* y hay hoja izquierda... */ if (hoja_izq!=nullptr) { Arbol_binario* tmp; /* busca la hoja más a la izquierda de la hoja derecha... */ for (tmp=hoja_der; tmp->hoja_izq!=nullptr; tmp=tmp->hoja_izq); /* y conéctale la hoja izquierda de esta hoja... */ tmp->hoja_izq=hoja_izq; } /* y haz esta hoja su hoja derecha. */ this->dato=hoja_der->dato; this->hoja_izq=hoja_der->hoja_izq; this->hoja_der=hoja_der->hoja_der; } /* Si no hay hoja derecha y hay hoja izquierda... */ else if (hoja_izq!=nullptr) { /* haz esta hoja su hoja izquierda. */ this->dato=hoja_izq->dato; this->hoja_der=hoja_izq->hoja_der; this->hoja_izq=hoja_izq->hoja_izq; } /* Si no hay hoja izquierda ni derecha, haz esta nula. */ else { this->dato=nullptr; this->hoja_der=this->hoja_izq=nullptr; } return dato; } /* Si la llave es menor que el dato de esta hoja, extrae por la izquierda. */ if (dif>0 && hoja_izq!=nullptr) return hoja_izq->extraer(llave,fcmp); /* Si la llave es mayor que el dato de esta hoja, extrae por la derecha. */ else if (dif<0 && hoja_der!=nullptr) return hoja_der->extraer(llave,fcmp); /* Si no hay más hojas, la llave no existe en el árbol. */ throw std::range_error {"extraer(): llave no existe en Arbol_binario"}; }
ATDouble Plane3D::Distance(const Point3D& point) const { ATDouble dist = std::fabs(A_ * point.x_ + B_ * point.y_ + C_ * point.z_ + D_); dist /= std::sqrt(A_ * A_ + B_ * B_ + C_ * C_); if (fcmp(dist, 0.0, EPSILON) == 0) return 0.0; return dist; }
void Plane3D::Init(const Point3D& P1, const Point3D& P2, const Point3D& P3) { Vector3D P2P1(P2.x_ - P1.x_, P2.y_ - P1.y_, P2.z_ - P1.z_); Vector3D P3P1(P3.x_ - P1.x_, P3.y_ - P1.y_, P3.z_ - P1.z_); normal = P2P1.CrossProduct(P3P1); A_ = normal.x_; B_ = normal.y_; C_ = normal.z_; D_ = -(A_ * P1.x_ + B_ * P1.y_ + C_ * P1.z_); if (fcmp(D_, 0.0, EPSILON) == 0) D_ = 0.0; }
bool Process(double P[]) { while(true) { int e=-1; double mV=-INF; for(int i=1; i<=nCnt; i++) if(fcmp(P[N[i]],mV)==1) mV=P[N[i]],e=N[i]; if(fcmp(mV,0.0)<=0) break; int l=-1; mV=INF; for(int i=1; i<=bCnt; i++) { if(fcmp(A[i][e],0.0)==1) { double t=b[i]/A[i][e]; if(fcmp(mV,t)==1||(fcmp(mV,t)==0&&(l==-1||B[l]>B[i]))) mV=t,l=i; } } if(l==-1) return false; Pivot(l,e); } return true; }
bool Plane3D::IsIntersecting(const Line3D& line, Point3D& intersec, ATDouble& t) const { intersec.SetPoint(INFINITY, INFINITY, INFINITY); t = 0.0; ATDouble numerator = - D_ - (A_ * line.P_.x_) - (B_ * line.P_.y_) - (C_ * line.P_.z_); ATDouble denominator = A_ * line.direction_vector_.x_ + B_ * line.direction_vector_.y_ + C_ * line.direction_vector_.z_; if (fcmp(denominator, 0.0, EPSILON) == 0) return false; t = numerator / denominator; intersec.x_ = line.P_.x_ + line.direction_vector_.x_ * t; intersec.y_ = line.P_.y_ + line.direction_vector_.y_ * t; intersec.z_ = line.P_.z_ + line.direction_vector_.z_ * t; // Check, if point is indeed on the plane, dot product of // the line direction vector and a normal of the plane should // be different than 0.0. if(fcmp(line.direction_vector_.DotProduct(normal), 0.0, EPSILON) != 0) return true; // Check, if point is indeed on the plane - distance // from a plane to a point should be equal to 0.0 if (fcmp(0.0, this->Distance(intersec), EPSILON) == 0) return true; return false; }
void addToTree(ttree* pTree, void* pdata, int (*fcmp)(void*,void*)) { if (pTree->pdata==NULL)pTree->pdata=pdata; else if (fcmp(pTree->pdata,pdata)>0) { if(pTree->pl==NULL){pTree->pl=malloc(sizeof(ttree));*(pTree->pl)=treeInit;} addToTree(pTree->pl,pdata,fcmp); } else { if(pTree->pr==NULL){pTree->pr=malloc(sizeof(ttree));*(pTree->pr)=treeInit;} addToTree(pTree->pr,pdata,fcmp); } }
void *lfv_search(void *key, void *base, size_t *num, size_t width, FCMP fcmp) { int i = 0, j; void *v; while (fcmp(BASE(i), key) != 0 && i < *num) i++; if (i >= *num) return NULL; v = malloc(width); memcpy(v, BASE(i), width); for (j = i+1; j < *num; j++) memcpy(BASE(j-1), BASE(j), width); for (j = *num-2; j >= 0; j--) memcpy(BASE(j+1), BASE(j), width); memcpy(base, v, width); return BASE(i); }
END_TEST START_TEST (test_video_resize) { Object * ev = obj_create ("video", NULL, NULL, NULL); VIDEO * v = obj_getClassData (ev, "video"); float x = 0, y = 0; obj_message (ev, OM_START, NULL, NULL); x = video_getXResolution (); y = video_getYResolution (); fail_unless ( fcmp (x, 67.2) && fcmp (y, 37.8), "Video default resolution should be 960x540 with a scale of 0.07" ); video_setScaling (v, 1.0); video_setResolution (v, 500.0, 500.0); x = video_getXResolution (); y = video_getYResolution (); fail_unless ( fcmp (x, 500.0) && fcmp (y, 500.0), "Video dimensions should be resizable on the fly (got %.2f, %.2f; expecting %.2f,%2.f)", x, y, 500.0, 500.0 ); video_setScaling (v, 2.0); x = video_getXResolution (); y = video_getYResolution (); fail_unless ( fcmp (x, 1000.0) && fcmp (y, 1000.0), "Video resolution should be resizable on the fly (got %.2f,%.2f; expecting %.2f,%.2f)", x, y, 1000.0, 1000.0 ); video_setScaling (v, 0.5); x = video_getXResolution (); y = video_getYResolution (); fail_unless ( fcmp (x, 250.0) && fcmp (y, 250.0), "Video resolution should be resizable on the fly (got %.2f,%.2f; expecting %.2f,%.2f)", x, y, 250.0, 250.0 ); obj_message (ev, OM_DESTROY, NULL, NULL); }
int is_center(struct Point * p) { int i; for (i = 0; i < pointsSize; ++i) { if (fcmp(sqr_dis2(i, p), R * R) > 0) { if (DEBUG) { printf("is_center for (%f, %f) return 0\n", p->x, p->y); } return 0; } } if (DEBUG) { printf("is_center for (%f, %f) return 1\n", p->x, p->y); } return 1; }
void Plane3D::SetPlane(const Point3D& A, const Point3D& B, const Point3D& C) { Vector3D AB(B, A); Vector3D CA(C, A); normal = AB.CrossProduct(CA); A_ = normal.x_; B_ = normal.y_; C_ = normal.z_; D_ = -(A_ * A.x_ + B_ * A.y_ + C_ * A.z_); //D_ = -(A_ * B.x + B_ * B.y + C_ * B.z); //D_ = -(A_ * C.x + B_ * C.y + C_ * C.z); if (fcmp(D_, 0.0, EPSILON) == 0) D_ = 0.0; }