stlplus::inf infsqrt(stlplus::inf &x) { stlplus::inf old(x); stlplus::inf newv(x / stlplus::inf(2)); while (old - newv > stlplus::inf(1)) { old = newv; newv = old - (old * old - x) / (stlplus::inf(2) * old); } return newv; }
void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) { if (id >= firstVarPropertyIndex) { if (!ensureVarPropertiesAllocated()) return; QV4::Scope scope(varProperties.engine()); // Importantly, if the current value is a scarce resource, we need to ensure that it // gets automatically released by the engine if no other references to it exist. QV4::ScopedObject vp(scope, varProperties.value()); QV4::Scoped<QV4::VariantObject> oldv(scope, vp->getIndexed(id - firstVarPropertyIndex)); if (!!oldv) oldv->removeVmePropertyReference(); // And, if the new value is a scarce resource, we need to ensure that it does not get // automatically released by the engine until no other references to it exist. QV4::ScopedValue newv(scope, QQmlEnginePrivate::get(ctxt->engine)->v8engine()->fromVariant(value)); QV4::Scoped<QV4::VariantObject> v(scope, newv); if (!!v) v->addVmePropertyReference(); // Write the value and emit change signal as appropriate. QVariant currentValue = readPropertyAsVariant(id); vp->putIndexed(id - firstVarPropertyIndex, newv); if ((currentValue.userType() != value.userType() || currentValue != value)) activate(object, methodOffset() + id, 0); } else { bool needActivate = false; if (value.userType() == QMetaType::QObjectStar) { QObject *o = *(QObject **)value.data(); needActivate = (data[id].dataType() != QMetaType::QObjectStar || data[id].asQObject() != o); data[id].setValue(o, this, id); } else { needActivate = (data[id].dataType() != qMetaTypeId<QVariant>() || data[id].asQVariant().userType() != value.userType() || data[id].asQVariant() != value); data[id].setValue(value); } if (needActivate) activate(object, methodOffset() + id, 0); } }
Vector Vector::normalize() const { double magnitude; Vector newv(N); magnitude = norm(); int i; for(i = 0; i < N; i++){ newv.v[i] = v[i] / magnitude; if(std::abs(v[i]) > magnitude * HUGENUMBER){ std::cerr << "taking the norm of a zero" << N << " Vector" << std::endl; break; } } for(; i < N; i++){ newv.v[i] = v[i] / magnitude; } return newv; }
int main() { double a; double e1 = 1.111; double e2 = 2.222; double e3 = 3.333; double e4 = 4.444; double e5 = 5.555; uVector *vector = newv(uVECTOR_TYPE_DOUBLE); vector->push_back(vector,&e1); vector->push_back(vector,&e2); vector->push_back(vector,&e3); vector->push_back(vector,&e4); vector->push_back(vector,&e5); a =*((double*)(vector->front(vector))); printf("%lf",a); return 0; }
void wfreadobj( /* read in .OBJ file and convert */ char *objfn ) { FILE *fp; char *argv[MAXARG]; int argc; int nstats, nunknown; if (objfn == NULL) { inpfile = "<stdin>"; fp = stdin; } else if ((fp = fopen(inpfile=objfn, "r")) == NULL) { sprintf(errmsg, "cannot open \"%s\"", inpfile); error(USER, errmsg); } havemats = (nobjects > 0); nstats = nunknown = 0; material[0] = '\0'; group[0] = '\0'; lineno = 0; faceno = 0; /* scan until EOF */ while ( (argc = getstmt(argv, fp)) ) { switch (argv[0][0]) { case 'v': /* vertex */ switch (argv[0][1]) { case '\0': /* point */ if (badarg(argc-1,argv+1,"fff")) syntax("bad vertex"); newv(atof(argv[1]), atof(argv[2]), atof(argv[3])); break; case 'n': /* normal */ if (argv[0][2]) goto unknown; if (badarg(argc-1,argv+1,"fff")) syntax("bad normal"); if (!newvn(atof(argv[1]), atof(argv[2]), atof(argv[3]))) syntax("zero normal"); break; case 't': /* coordinate */ if (argv[0][2]) goto unknown; if (badarg(argc-1,argv+1,"ff")) goto unknown; newvt(atof(argv[1]), atof(argv[2])); break; default: goto unknown; } break; case 'f': /* face */ if (argv[0][1]) goto unknown; faceno++; switch (argc-1) { case 0: case 1: case 2: syntax("too few vertices"); break; case 3: if (!puttri(argv[1], argv[2], argv[3])) syntax("bad triangle"); break; default: if (!putface(argc-1, argv+1)) syntax("bad face"); break; } break; case 'u': /* usemtl/usemap */ if (!strcmp(argv[0], "usemap")) break; if (strcmp(argv[0], "usemtl")) goto unknown; if (argc > 1) strcpy(material, argv[1]); else material[0] = '\0'; break; case 'o': /* object name */ if (argv[0][1]) goto unknown; break; case 'g': /* group name */ if (argv[0][1]) goto unknown; if (argc > 1) strcpy(group, argv[1]); else group[0] = '\0'; break; case '#': /* comment */ break; default:; /* something we don't deal with */ unknown: nunknown++; break; } nstats++; } /* clean up */ freeverts(); fclose(fp); if (nunknown > 0) { sprintf(errmsg, "%d of %d statements unrecognized", nunknown, nstats); error(WARNING, errmsg); } }
void convert( /* convert an OBJ stream */ FILE *fp ) { char *argv[MAXARG]; int argc; int nstats, nunknown; int i; nstats = nunknown = 0; /* scan until EOF */ while ( (argc = getstmt(argv, fp)) ) { switch (argv[0][0]) { case 'v': /* vertex */ switch (argv[0][1]) { case '\0': /* point */ if (badarg(argc-1,argv+1,"fff")) syntax("Bad vertex"); newv(atof(argv[1]), atof(argv[2]), atof(argv[3])); break; case 'n': /* normal */ if (argv[0][2]) goto unknown; if (badarg(argc-1,argv+1,"fff")) syntax("Bad normal"); if (!newvn(atof(argv[1]), atof(argv[2]), atof(argv[3]))) syntax("Zero normal"); break; case 't': /* texture map */ if (argv[0][2]) goto unknown; if (badarg(argc-1,argv+1,"ff")) goto unknown; newvt(atof(argv[1]), atof(argv[2])); break; default: goto unknown; } break; case 'f': /* face */ if (argv[0][1]) goto unknown; faceno++; switch (argc-1) { case 0: case 1: case 2: syntax("Too few vertices"); break; case 3: if (!puttri(argv[1], argv[2], argv[3])) syntax("Bad triangle"); break; default: if (!putface(argc-1, argv+1)) syntax("Bad face"); break; } break; case 'u': if (!strcmp(argv[0], "usemtl")) { /* material */ if (argc < 2) break; /* not fatal */ strcpy(matname, argv[1]); } else if (!strcmp(argv[0], "usemap")) {/* map */ if (argc < 2) break; /* not fatal */ if (!strcmp(argv[1], "off")) mapname[0] = '\0'; else sprintf(mapname, "%s.hdr", argv[1]); } else goto unknown; break; case 'o': /* object name */ if (argv[0][1]) goto unknown; if (argc < 2) break; /* not fatal */ strcpy(objname, argv[1]); break; case 'g': /* group name(s) */ if (argv[0][1]) goto unknown; for (i = 1; i < argc; i++) strcpy(group[i-1], argv[i]); group[argc-1][0] = '\0'; break; case '#': /* comment */ printargs(argc, argv, stdout); break; default:; /* something we don't deal with */ unknown: nunknown++; break; } nstats++; } printf("\n# Done processing file: %s\n", inpfile); printf("# %d lines, %d statements, %d unrecognized\n", lineno, nstats, nunknown); }