ull* productFib(ull prod) { ull *out = malloc(3 * sizeof(ull*)); ull isfib = 1; long double golden = 1.6180339887498948482; long double srfive = 2.2360679774997896964; long double p = (long double)prod; long double n, m, r, t; n = roundl(sqrtl(p / golden)); m = p / n; r = fmodl(p, n); if (r > 0) { isfib = 0; t = floorl(logl(n * srfive) / logl(golden)) + 1; n = roundl(powl(golden, t) / srfive); m = roundl(powl(golden, t + 1) / srfive); } out[0] = (ull)n; out[1] = (ull)m; out[2] = isfib; return out; }
//---------------------------------------------------------------------------- void vtkInteractorStyleGame::OnMouseMove() { if(this->CurrentRenderer == NULL){ return; } vtkRenderWindowInteractor *rwi = this->Interactor; vtkXOpenGLRenderWindow *rw = static_cast<vtkXOpenGLRenderWindow *>(rwi->GetRenderWindow()); int *size = rw->GetSize(); int *eventPos = rwi->GetEventPosition(); Window Win = rw->GetWindowId(); Display* Disp = rw->GetDisplayId(); if(eventPos[0] < size[0] && eventPos[1] < size[1]){ mousedt.x += rwi->GetEventPosition()[0] - roundl(size[0]/2); mousedt.y += (rwi->GetEventPosition()[1] +1) - roundl(size[1]/2); } else{ mousedt.x = 0; mousedt.y = 0; } // Warp mouse to center of screen to grap the mouse XWarpPointer(Disp, Win, Win, 0,0,size[0],size[1], roundl(size[0]/2), roundl(size[1]/2)); }
void shoes_plot_draw_scatter_pts(cairo_t *cr, shoes_plot *plot) { // first series (x) controls graphical settings. if (plot->seriescnt != 2) return; // we don't have just two series int i; int top,left,bottom,right; left = plot->graph_x; top = plot->graph_y; right = plot->graph_w; bottom = plot->graph_h; int height = bottom - top; int width = right - left; VALUE rbxser, rbyser; shoes_chart_series *serx, *sery; rbxser = rb_ary_entry(plot->series, 0); Data_Get_Struct(rbxser, shoes_chart_series, serx); rbyser = rb_ary_entry(plot->series, 1); Data_Get_Struct(rbyser, shoes_chart_series, sery); double xmax = NUM2DBL(serx->maxv); double ymax = NUM2DBL(sery->maxv); double xmin = NUM2DBL(serx->minv); double ymin = NUM2DBL(sery->minv); int nubs = NUM2INT(serx->point_type); VALUE shcolor = serx->color; VALUE rbstroke = serx->strokes; int strokew = NUM2INT(rbstroke); if (strokew < 1) strokew = 1; shoes_color *color; Data_Get_Struct(shcolor, shoes_color, color); int obvs = RARRAY_LEN(serx->values); for (i = 0; i < obvs; i++) { double xval, yval; xval = NUM2DBL(rb_ary_entry(serx->values, i)); yval = NUM2DBL(rb_ary_entry(sery->values, i)); //printf("scatter x: %f, y: %f\n", xval, yval); } double yScale = height / (ymax - ymin); double xScale = width / (xmax - xmin); cairo_set_source_rgba(cr, color->r / 255.0, color->g / 255.0, color->b / 255.0, color->a / 255.0); for (i = 0; i < obvs; i++) { VALUE rbx = rb_ary_entry(serx->values, i); double xval = NUM2DBL(rbx); VALUE rby = rb_ary_entry(sery->values, i); double yval = NUM2DBL(rby); long x = roundl((xval - xmin) * xScale); long y = height - roundl((yval - ymin) * yScale); x += left; y += top; //printf("x: %f, y: %f --> x: %i px, y: %i, px\n", xval, yval, x, y); // lets draw a nub at x, y cairo_move_to(cr, x, y); shoes_plot_draw_nub(cr, plot, x, y, nubs, strokew + 2); } cairo_stroke(cr); shoes_plot_set_cairo_default(cr, plot); }
std::string Stopwatch::ToDaysString() const { const long double days = roundl(Seconds() / (60.0*60.0))/24.0; std::stringstream str; if(days >= 10.0) str << roundl(days) << " days"; else str << floorl(days) << 'd' << (days*24.0) << 'h'; return str.str(); }
std::string Stopwatch::ToNanoSecondsString() const { const long double nsec = roundl(Seconds()*10000000000.0)/10.0; std::stringstream str; if(nsec >= 10.0) str << roundl(Seconds()*1000000000.0) << "ns"; else str << nsec << "ns"; return str.str(); }
std::string Stopwatch::ToSecondsString() const { const long double seconds = roundl(Seconds()*10.0)/10.0; std::stringstream str; if(seconds >= 10.0) str << roundl(Seconds()) << 's'; else str << seconds << 's'; return str.str(); }
std::string Stopwatch::ToMinutesString() const { const long double mins = roundl(Seconds())/60.0; std::stringstream str; if(mins >= 10.0) str << roundl(mins) << " min"; else str << floorl(mins) << 'm' << fmod(mins*60.0,60.0) << 's'; return str.str(); }
std::string Stopwatch::ToHoursString() const { const long double hours = roundl(Seconds() / 60.0)/60.0; std::stringstream str; if(hours >= 10.0) str << roundl(hours) << 'h'; else str << floorl(hours) << 'h' << (hours*60.0) << 'm'; return str.str(); }
std::string Stopwatch::ToMilliSecondsString() const { const long double msec = roundl(Seconds()*10000.0)/10.0; std::stringstream str; if(msec >= 10.0) str << roundl(Seconds()*1000.0) << "ms"; else str << msec << "ms"; return str.str(); }
int main () { DECL_LONG_DOUBLE_ROUNDING BEGIN_LONG_DOUBLE_ROUNDING (); /* See IEEE 754, section 6.3: "the sign of the result of the round floating-point number to integral value operation is the sign of the operand. These rules shall apply even when operands or results are zero or infinite." */ /* Zero. */ ASSERT (!signbit (roundl (0.0L))); ASSERT (!!signbit (roundl (minus_zerol)) == !!signbit (minus_zerol)); /* Positive numbers. */ ASSERT (!signbit (roundl (0.3L))); ASSERT (!signbit (roundl (0.7L))); /* Negative numbers. */ ASSERT (!!signbit (roundl (-0.3L)) == !!signbit (minus_zerol)); ASSERT (!!signbit (roundl (-0.7L)) == !!signbit (minus_zerol)); /* [MX] shaded specification in POSIX. */ /* NaN. */ ASSERT (isnanl (roundl (NaNl ()))); /* Infinity. */ ASSERT (roundl (Infinityl ()) == Infinityl ()); ASSERT (roundl (- Infinityl ()) == - Infinityl ()); return 0; }
int main(){ int t, n; //(1 <= T <= 10^5) (n >= 1 && n <= 10^9) fast_scani(&t); while(t--){ fast_scani(&n); if((n&1)){ // faster than printf("%.Lf\n", roundl(1.0l*(n+3)*(n+3)/48.0)); printf("%lld\n", (unsigned long long)roundl(1.0l*(n+3)*(n+3)/48.0)); } else{ printf("%lld\n", (unsigned long long)roundl(1.0l*n*n/48.0)); } } return 0; }
void test_round() { static_assert((std::is_same<decltype(round((double)0)), double>::value), ""); static_assert((std::is_same<decltype(roundf(0)), float>::value), ""); static_assert((std::is_same<decltype(roundl(0)), long double>::value), ""); assert(round(1) == 1); }
void check_functions(void) { long double *a = malloc(sizeof(long double)); *a = 46; hashtbl_insert(vars, "a", a); ASSERT_EQ(evaluate("max(10, 20, 12, 15)"), 20); ASSERT_EQ(evaluate("min(11, 21, 15, 25)"), 11); ASSERT_EQ(evaluate("sum(1, 2, 3, 4, 5, 6)"), 21); ASSERT_EQ(evaluate("avg(3.4, 4e-2, 3.5, a)"), 13.235); ASSERT_EQ(evaluate("abs(-34)"), 34); *a = evaluate("random()"); ASSERT_EQ(evaluate("cos(a)**2 + sin(a)**2"), 1.0); ASSERT_EQ(evaluate("sin(phi)/cos(phi) - tan(phi)"), 0.0); ASSERT_EQ(evaluate("1 + tan(a)**2 - 1/cos(a)**2"), 0.0); ASSERT_EQ(evaluate("atan2(a, phi) == atan(a/phi)"), 1); ASSERT_EQ(evaluate("acos(cos(phi)) - phi"), 0.0); ASSERT_EQ(evaluate("asin(sin(phi/4)) == phi/4"), 1); ASSERT_EQ(evaluate("log(exp(3))"), 3); ASSERT_EPS(evaluate("log(234 * 4234) - log(234) - log(4234)"), 0.0, 1.0e-5); ASSERT_EQ(roundl(evaluate("gamma(16)")), 1307674368000); }
long double floorl(long double x) { long double y; y = roundl(x); return (y <= x) ? y : y - 1.0; }
long double ceill(long double x) { long double y; y = roundl(x); return (y >= x) ? y : y + 1.0; }
// ---------------------------------------------------------------------------- // Description: // Timer set on each render step. Handle mouse, keyboard and gamepad movement and move the camera accordingly. void vtkInteractorStyleGame::OnTimer() { vtkRenderWindowInteractor *rwi = this->Interactor; vtkXOpenGLRenderWindow *rw = static_cast<vtkXOpenGLRenderWindow *>(rwi->GetRenderWindow()); int *size = rw->GetSize(); Window Win = rw->GetWindowId(); Display* Disp = rw->GetDisplayId(); if (this->gamepad->IsActive()) { // Get updated gamepad state this->handleGamepadState(this->gamepad->getGamepadState()); } double dt = ((double)(clock() - t))/CLOCKS_PER_SEC; t = clock(); if(this->gamepadSpeed.y != 0 || this->keyboardSpeed.y != 0) this->MoveToFocalPoint(dt); if(this->gamepadSpeed.x != 0 || this->keyboardSpeed.x != 0) this->Pan(dt); if(this->gamepadRoll != 0 || this->keyboardRoll != 0) this->CameraRoll(dt); if(this->gamepaddt.x !=0) //this->ModelRotate(dt); this->CameraYaw(dt); if(this->gamepaddt.y !=0) this->Up(dt); //this->CameraPitch(dt); if(this->flying) this->Fly(dt); if (this->modelRotateSpeed != 0) { //printf("modelRotateSpeed = %g\n", this->modelRotateSpeed); this->ModelRotate(dt); } //if(this->rotate) //this->Rotate(dt); mousedt.x = 0; mousedt.y = 0; XWarpPointer(Disp, Win, Win, 0,0,size[0],size[1], roundl(size[0]/2), roundl(size[1]/2)); }
int isInt(long double n){ long double r = roundl(n); n -= r; if(n < 0){ n = -n; } return n <= EPSILON; }
//#TPT-Directive ElementHeader Element_PSNS static int update(UPDATE_FUNC_ARGS) int Element_PSNS::update(UPDATE_FUNC_ARGS) { int r, rx, ry, rt; if ((parts[i].tmp == 0 && sim->pv[y/CELL][x/CELL] > parts[i].temp-273.15f) || (parts[i].tmp == 2 && sim->pv[y/CELL][x/CELL] < parts[i].temp-273.15f)) { parts[i].life = 0; for (rx = -2; rx <= 2; rx++) for (ry = -2; ry <= 2; ry++) if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y+ry][x+rx]; if (!r) continue; if (sim->parts_avg(i,ID(r),PT_INSL) != PT_INSL) { rt = TYP(r); if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[ID(r)].life==0) { parts[ID(r)].life = 4; parts[ID(r)].ctype = rt; sim->part_change_type(ID(r),x+rx,y+ry,PT_SPRK); } } } } if (parts[i].tmp == 1) { parts[i].life = 0; bool setFilt = true; float photonWl = sim->pv[y / CELL][x / CELL]; if (setFilt) { int nx, ny; for (rx = -1; rx <= 1; rx++) for (ry = -1; ry <= 1; ry++) if (BOUNDS_CHECK && (rx || ry)) { r = pmap[y + ry][x + rx]; if (!r) continue; nx = x + rx; ny = y + ry; while (TYP(r) == PT_FILT) { parts[ID(r)].ctype = 0x10000000 + roundl(photonWl) + 256; nx += rx; ny += ry; if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) break; r = pmap[ny][nx]; } } } } return 0; }
inline static struct minmaxmean calc_min_max_mean_gap(struct slist *list, int decim8, int rxtx) { struct slist *ln; int32_t size = slist_size(list); int32_t gap_lengths[MAX_LIST_LEN] = { 0 }; int32_t gap_idx = 0; int found_gap = 0; int32_t min_gap = decim8 + 1; int32_t max_gap = 0; int32_t sum_gap = 0; int32_t mean_gap = 0; assert(size >= decim8); assert(decim8 > 0); ln = slist_idx(list, size - decim8); for (int i = decim8; i > 0; i--) { struct sample *s = ln->s; if (((RX == rxtx) && (0 == s->rx_packets_delta)) || ((TX == rxtx) && (0 == s->tx_packets_delta))) { found_gap = 1; gap_lengths[gap_idx]++; max_gap = (max_gap > gap_lengths[gap_idx]) ? max_gap : gap_lengths[gap_idx]; } else if (found_gap) { found_gap = 0; gap_idx++; } ln = ln->next; } assert(gap_idx <= decim8); assert(max_gap <= decim8); for (int i = 0; i <= gap_idx; i++) { sum_gap += gap_lengths[i]; if (min_gap > gap_lengths[i]) { min_gap = gap_lengths[i]; } } assert(sum_gap <= decim8); assert((min_gap <= decim8) || (sum_gap == 0)); /* gap is the last index into the gap_lengths, so +1 for count. */ mean_gap = roundl((1000.0 * sum_gap) / (gap_idx + 1)); assert(1000 * min_gap <= mean_gap); return (struct minmaxmean){min_gap, max_gap, mean_gap}; }
TEST(math, roundl) { fesetround(FE_TOWARDZERO); // roundl ignores the rounding mode and always rounds away from zero. ASSERT_FLOAT_EQ(1.0, roundl(0.5)); ASSERT_FLOAT_EQ(-1.0, roundl(-0.5)); ASSERT_FLOAT_EQ(0.0, roundl(0.0)); ASSERT_FLOAT_EQ(-0.0, roundl(-0.0)); ASSERT_TRUE(isnan(roundl(nanl("")))); ASSERT_FLOAT_EQ(HUGE_VALL, roundl(HUGE_VALL)); }
TEST(math, roundl) { auto guard = make_scope_guard([]() { fesetenv(FE_DFL_ENV); }); fesetround(FE_TOWARDZERO); // roundl ignores the rounding mode and always rounds away from zero. ASSERT_DOUBLE_EQ(1.0L, roundl(0.5L)); ASSERT_DOUBLE_EQ(-1.0L, roundl(-0.5L)); ASSERT_DOUBLE_EQ(0.0L, roundl(0.0L)); ASSERT_DOUBLE_EQ(-0.0L, roundl(-0.0L)); ASSERT_TRUE(isnan(roundl(nanl("")))); ASSERT_DOUBLE_EQ(HUGE_VALL, roundl(HUGE_VALL)); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs == 3) { int netid = (int)mxGetScalar(prhs[0]); size_t nodeid = (size_t)roundl(mxGetScalar(prhs[1])); size_t i; mxArray *updatedNodes = (mxArray *)NULL; for (i = 0; i < 1; i++) { mxArray *val = mxDuplicateArray(prhs[2]); mexMakeArrayPersistent(val); updatedNodes = sqTransact(netid, nodeid, val); } if (updatedNodes) plhs[0] = updatedNodes; } else { mexErrMsgIdAndTxt("sq:notEnoughArgs", "Not enough input arguments"); } }
bool allow_create_attempt(JSON& attempt, const JSON& problem) { int cid; if (!problem("contest").read(cid)) return true; DB(contests); JSON contest = contests.retrieve(cid); if (contest("finished")) return true; if (isjudge(attempt["user"],contest)) { attempt["contest"] = cid; attempt["privileged"].settrue(); return true; } auto t = time(contest); time_t when = attempt["when"]; if (t.begin <= when && when < t.end) { attempt["contest"] = cid; attempt["contest_time"] = int(roundl((when-t.begin)/60.0L)); return true; } return false; }
long double powl(long double x, long double y) { long double ret; if(x == 1.0 || y == 0.0) return 1.0; if(isnan(x)) return x; else if(isnan(y)) return y; if(x < 0.0 || roundl(y) != y) { /* XXX really report the error */ errno = EDOM; return 0.0; } if(x == 0.0 && y > 0.0) return 0.0; /* XXX there are more corner cases with infinity */ for(ret = 1.0; y >= 1.0; y -= 1.0) /* FIXME detect overflows and underflows */ ret = ret * x; return ret; }
int run_test(struct test *test) { fprintf(stderr, "\nRunning test '%s':\n%s\n", test->name, test->description); rrd_memory_mode = RRD_MEMORY_MODE_RAM; rrd_update_every = test->update_every; char name[101]; snprintfz(name, 100, "unittest-%s", test->name); // create the chart RRDSET *st = rrdset_create("netdata", name, name, "netdata", NULL, "Unit Testing", "a value", 1, test->update_every, RRDSET_TYPE_LINE); RRDDIM *rd = rrddim_add(st, "dim1", NULL, test->multiplier, test->divisor, test->algorithm); RRDDIM *rd2 = NULL; if(test->feed2) rd2 = rrddim_add(st, "dim2", NULL, test->multiplier, test->divisor, test->algorithm); st->debug = 1; // feed it with the test data time_t time_now = 0, time_start = now_realtime_sec(); unsigned long c; collected_number last = 0; for(c = 0; c < test->feed_entries; c++) { if(debug_flags) fprintf(stderr, "\n\n"); if(c) { time_now += test->feed[c].microseconds; fprintf(stderr, " > %s: feeding position %lu, after %0.3f seconds (%0.3f seconds from start), delta " CALCULATED_NUMBER_FORMAT ", rate " CALCULATED_NUMBER_FORMAT "\n", test->name, c+1, (float)test->feed[c].microseconds / 1000000.0, (float)time_now / 1000000.0, ((calculated_number)test->feed[c].value - (calculated_number)last) * (calculated_number)test->multiplier / (calculated_number)test->divisor, (((calculated_number)test->feed[c].value - (calculated_number)last) * (calculated_number)test->multiplier / (calculated_number)test->divisor) / (calculated_number)test->feed[c].microseconds * (calculated_number)1000000); rrdset_next_usec_unfiltered(st, test->feed[c].microseconds); } else { fprintf(stderr, " > %s: feeding position %lu\n", test->name, c+1); } fprintf(stderr, " >> %s with value " COLLECTED_NUMBER_FORMAT "\n", rd->name, test->feed[c].value); rrddim_set(st, "dim1", test->feed[c].value); last = test->feed[c].value; if(rd2) { fprintf(stderr, " >> %s with value " COLLECTED_NUMBER_FORMAT "\n", rd2->name, test->feed2[c]); rrddim_set(st, "dim2", test->feed2[c]); } rrdset_done(st); // align the first entry to second boundary if(!c) { fprintf(stderr, " > %s: fixing first collection time to be %llu microseconds to second boundary\n", test->name, test->feed[c].microseconds); rd->last_collected_time.tv_usec = st->last_collected_time.tv_usec = st->last_updated.tv_usec = test->feed[c].microseconds; // time_start = st->last_collected_time.tv_sec; } } // check the result int errors = 0; if(st->counter != test->result_entries) { fprintf(stderr, " %s stored %lu entries, but we were expecting %lu, ### E R R O R ###\n", test->name, st->counter, test->result_entries); errors++; } unsigned long max = (st->counter < test->result_entries)?st->counter:test->result_entries; for(c = 0 ; c < max ; c++) { calculated_number v = unpack_storage_number(rd->values[c]); calculated_number n = test->results[c]; int same = (roundl(v * 10000000.0) == roundl(n * 10000000.0))?1:0; fprintf(stderr, " %s/%s: checking position %lu (at %lu secs), expecting value " CALCULATED_NUMBER_FORMAT ", found " CALCULATED_NUMBER_FORMAT ", %s\n", test->name, rd->name, c+1, (rrdset_first_entry_t(st) + c * st->update_every) - time_start, n, v, (same)?"OK":"### E R R O R ###"); if(!same) errors++; if(rd2) { v = unpack_storage_number(rd2->values[c]); n = test->results2[c]; same = (roundl(v * 10000000.0) == roundl(n * 10000000.0))?1:0; fprintf(stderr, " %s/%s: checking position %lu (at %lu secs), expecting value " CALCULATED_NUMBER_FORMAT ", found " CALCULATED_NUMBER_FORMAT ", %s\n", test->name, rd2->name, c+1, (rrdset_first_entry_t(st) + c * st->update_every) - time_start, n, v, (same)?"OK":"### E R R O R ###"); if(!same) errors++; } } return errors; }
cv::Mat PedestrianFeatureMap::compute(int frame) { cv::Mat img = m_frame.color; std::vector<cv::Rect> found, found_filtered; std::vector<double> weights; m_HOG.detectMultiScale(img, found, weights, 0.7, cv::Size(8,8), cv::Size(32,32), 1.05, 2); for (size_t i = 0 ; i < found.size() ; i++) { cv::Rect r = found[i]; found_filtered.push_back(r); } cv::Mat smap(img.size(), CV_32FC1, cv::Scalar(0.f)); for (size_t i = 0 ; i < found_filtered.size() ; i++) { cv::Rect r2 = found_filtered[i]; r2.x += roundl(r2.width*0.1); r2.width = roundl(r2.width*0.8); r2.y += roundl(r2.height*0.06); r2.height = roundl(r2.height*0.9); // show bounding box // cv::rectangle(img, r2.tl(), r2.br(), cv::Scalar(0,255*weights[i],0), 2); cv::rectangle(smap, r2.tl(), r2.br(), cv::Scalar(1), cv::FILLED); } if(m_FaceCascadeEnabled) { cv::Mat gray; cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY); cv::resize(gray, gray, cv::Size(1400, 788)); std::vector<cv::Rect> faceFeatures; if (m_FaceCascadeEnabled) m_face_cascade.detectMultiScale(gray, faceFeatures, 1.1, 2, 0 | cv::CASCADE_SCALE_IMAGE, cv::Size(15, 15)); float scalingFactorX = static_cast<float>(img.cols) / 1400.f; float scalingFactorY = static_cast<float>(img.rows) / 788.f; for (size_t i = 0; i < faceFeatures.size(); ++i) { cv::Rect r2 = faceFeatures[i]; r2.x *= scalingFactorX; r2.y *= scalingFactorY; r2.width *= scalingFactorX; r2.height *= scalingFactorY; r2.x += roundl(r2.width*0.1); r2.width = roundl(r2.width*0.8); r2.y += roundl(r2.height*0.06); r2.height = roundl(r2.height*0.9); cv::rectangle(smap, r2.tl(), r2.br(), cv::Scalar(1), cv::FILLED); } } return smap; }
void shoes_plot_draw_ticks_and_labels(cairo_t *cr, shoes_plot *plot) { int top, left, bottom, right; // these are cairo abs for plot->graph int width, height; // full plot space so it includes everything int range; int h_padding = 65; // default width of horizontal tick cell TODO: an option in plot-> int v_padding = 25; // default height of tick TODO: an option in plot-> left = plot->graph_x; top = plot->graph_y; right = plot->graph_w; bottom = plot->graph_h; range = plot->end_idx - plot->beg_idx; width = right - left; height = bottom - top; h_padding = width / plot->x_ticks; v_padding = height / plot->y_ticks; double h_scale; int h_interval; h_scale = width / (double) (range -1); h_interval = (int) ceil(h_padding / h_scale); // draw x axis - labels and tick mark uses series[0]->labels[*] - assumes it's strings // in the array -- TODO: allow a proc to be called to create the string. at 'i' int i; VALUE rbxser; shoes_chart_series *serx; rbxser = rb_ary_entry(plot->series, 0); Data_Get_Struct(rbxser, shoes_chart_series, serx); VALUE xobs = serx->labels; if (NIL_P(xobs) || TYPE(xobs) != T_ARRAY) rb_raise (rb_eArgError, "xobs must be an array"); for (i = 0 ; i < range; i++ ) { int x = (int) roundl(i * h_scale); x += left; long y = bottom; if ((i % h_interval) == 0) { char *rawstr; VALUE rbstr = rb_ary_entry(xobs, i + plot->beg_idx); if (NIL_P(rbstr)) { rawstr = " "; } else { rawstr = RSTRING_PTR(rbstr); } //printf("x label i: %i, x: %i, y: %i, \"%s\" %i %f \n", i, (int) x, (int) y, rawstr, h_interval, h_scale); shoes_plot_draw_tick(cr, plot, x, y, VERTICALLY); if (plot->chart_type == LINE_CHART || plot->chart_type == TIMESERIES_CHART) shoes_plot_draw_label(cr, plot, x, y, rawstr, BELOW); } } int j; for (j = 0; j < min(2, plot->seriescnt); j++) { VALUE rbser = rb_ary_entry(plot->series, j); shoes_chart_series *cs; Data_Get_Struct(rbser, shoes_chart_series, cs); double maximum = NUM2DBL(cs->maxv); double minimum = NUM2DBL(cs->minv); double v_scale = height / (maximum - minimum); int v_interval = (int) ceil(v_padding / v_scale); char tstr[16]; long i; for (i = ((long) minimum) + 1 ; i < ((long) roundl(maximum)); i = i + roundl(v_interval)) { int y = (int) (bottom - roundl((i - minimum) * v_scale)); int x = 0; sprintf(tstr, "%i", (int)i); // TODO user specificed format? if (j == 0) { // left side y presentation x = left; //printf("hoz left %i, %i, %s\n", (int)x, (int)y,tstr); shoes_plot_draw_tick(cr, plot, x, y, HORIZONTALLY); shoes_plot_draw_label(cr, plot, x, y, tstr, LEFT); } else { // right side y presentation x = right; shoes_plot_draw_tick(cr, plot, x, y, HORIZONTALLY); shoes_plot_draw_label(cr, plot, x, y, tstr, RIGHT); } } } }
/** * Group: * C * * Function: * Gua_Status Glo_FunctionWrapper(void *nspace, Gua_Short argc, Gua_Object *argv, Gua_Object *object, Gua_String error) * * Description: * Function wrapper. * * Arguments: * nspace, a pointer to a structure Gua_Namespace. Must do a cast before use it; * argc, the number of arguments to pass to the function; * argv, an array containing the arguments to the function; * argv[0] is the function name; * object, a structure containing the return object of the function; * error, a pointer to the error message. * * Results: * The return object of the wrapped function. */ Gua_Status Glo_FunctionWrapper(void *nspace, Gua_Short argc, Gua_Object *argv, Gua_Object *object, Gua_String error) { GLint arg2i; GLint arg3i; GLfloat arg3f; GLMmodel *model; GLuint model_list; Gua_Object o; FILE *fp; Gua_String errMessage; arg2i = 0; arg3f = 0.0; model = NULL; model_list = 0; if (argc == 0) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s\n", "no function specified"); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } /** * Group: * Scripting * * Function: * gloLoadObj(file, modifiers, degree) * * Description: * Load an OBJ file and returns an OpenGL list. * * Examples: * output == annProcess(ann, input, dim_in_j, dim_out_j). */ if (strcmp(Gua_ObjectToString(argv[0]), "gloLoadObj") == 0) { if (argc != 4) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "wrong number of arguments for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (Gua_ObjectType(argv[1]) != OBJECT_TYPE_STRING) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 1 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (!((Gua_ObjectType(argv[2]) == OBJECT_TYPE_INTEGER) || (Gua_ObjectType(argv[2]) == OBJECT_TYPE_REAL))) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 2 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (!((Gua_ObjectType(argv[3]) == OBJECT_TYPE_INTEGER) || (Gua_ObjectType(argv[3]) == OBJECT_TYPE_REAL))) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 3 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (Gua_ObjectType(argv[2]) == OBJECT_TYPE_INTEGER) { arg2i = Gua_ObjectToInteger(argv[2]); } else if (Gua_ObjectType(argv[2]) == OBJECT_TYPE_REAL) { arg2i = roundl(Gua_ObjectToReal(argv[2])); } if (Gua_ObjectType(argv[3]) == OBJECT_TYPE_INTEGER) { arg3f = Gua_ObjectToInteger(argv[3]); } else if (Gua_ObjectType(argv[3]) == OBJECT_TYPE_REAL) { arg3f = Gua_ObjectToReal(argv[3]); } /* * Reads the model data, defines its vertices normals * and create an OpenGL list to reference the object. */ model = glmReadOBJ(Gua_ObjectToString(argv[1])); glmUnitize(model); glmFacetNormals(model); glmVertexNormals(model, arg3f); model_list = glmList(model, arg2i); Gua_IntegerToPObject(object, model_list); /** * Group: * Scripting * * Function: * gloLoadPPM(file, "width", "height") * * Description: * Load a PPM image file. * * Examples: * texture = gloLoadPPM($texture_file, "texture_width", "texture_height"). */ } else if (strcmp(Gua_ObjectToString(argv[0]), "gloLoadPPM") == 0) { if (argc != 4) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "wrong number of arguments for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (Gua_ObjectType(argv[1]) != OBJECT_TYPE_STRING) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 1 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (Gua_ObjectType(argv[2]) != OBJECT_TYPE_STRING) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 1 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (Gua_ObjectType(argv[3]) != OBJECT_TYPE_STRING) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 1 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } Gua_LinkByteArrayToPObject(object, (Gua_String)Glo_LoadPPM(Gua_ObjectToString(argv[1]), &arg2i, &arg3i), arg2i * arg3i * 3); Gua_IntegerToObject(o, arg2i); Gua_SetStoredObject(o); if (Gua_SetVariable((Gua_Namespace *)nspace, Gua_ObjectToString(argv[2]), &o, SCOPE_STACK) != GUA_OK) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "can't set variable", Gua_ObjectToString(argv[2])); strcat(error, errMessage); Gua_Free(errMessage); } Gua_IntegerToObject(o, arg3i); Gua_SetStoredObject(o); if (Gua_SetVariable((Gua_Namespace *)nspace, Gua_ObjectToString(argv[3]), &o, SCOPE_STACK) != GUA_OK) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "can't set variable", Gua_ObjectToString(argv[3])); strcat(error, errMessage); Gua_Free(errMessage); } /** * Group: * Scripting * * Function: * gloSavePPM(texture, file, width, height) * * Description: * Save a PPM image file. * * Examples: * gloSavePPM(texture, "/tmp/texture.ppm", $texture_width, $texture_height). */ } else if (strcmp(Gua_ObjectToString(argv[0]), "gloSavePPM") == 0) { if (argc != 5) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "wrong number of arguments for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (Gua_ObjectType(argv[1]) != OBJECT_TYPE_STRING) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 1 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (Gua_ObjectType(argv[2]) != OBJECT_TYPE_STRING) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 2 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (!((Gua_ObjectType(argv[3]) == OBJECT_TYPE_INTEGER) || (Gua_ObjectType(argv[3]) == OBJECT_TYPE_REAL))) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 3 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } if (!((Gua_ObjectType(argv[4]) == OBJECT_TYPE_INTEGER) || (Gua_ObjectType(argv[4]) == OBJECT_TYPE_REAL))) { errMessage = (Gua_String) Gua_Alloc(sizeof(char) * MAX_ERROR_MSG_SIZE + 1); sprintf(errMessage, "%s %-.20s...\n", "illegal argument 4 for function", Gua_ObjectToString(argv[0])); strcat(error, errMessage); Gua_Free(errMessage); return GUA_ERROR; } /* * Open the PPM image file. */ fp = fopen(Gua_ObjectToString(argv[2]), "w+"); if (fp != NULL) { /* * Writes the PPM file header. */ fputs("P6\n", fp); fprintf(fp, "%ld %ld\n", Gua_ObjectToInteger(argv[3]), Gua_ObjectToInteger(argv[4])); fputs("255\n", fp); /* * Writes the raw image data. */ fwrite(Gua_ObjectToString(argv[1]), sizeof(char), Gua_ObjectToInteger(argv[3]) * Gua_ObjectToInteger(argv[4]) * 3, fp); fclose(fp); } } return GUA_OK; }
int get_PSRFITS_rawblock(float *fdata, struct spectra_info *s, int *padding) // This routine reads a single block (i.e subint) from the input files // which contain raw data in PSRFITS format. If padding is // returned as 1, then padding was added and statistics should not be // calculated. Return 1 on success. { int numtopad = 0, numtoread, status = 0, anynull; float *fdataptr = fdata; fdataptr = fdata + numbuffered * s->num_channels; // numtoread is always this size since we need to read // full PSRFITS subints... numtoread = s->spectra_per_subint; // If our buffer array is offset from last time, // copy the previously offset part into the beginning. // New data comes after the old data in the buffer. if (numbuffered) memcpy((char *) fdata, (char *) (fdata + numtoread * s->num_channels), numbuffered * s->num_channels * sizeof(float)); // Make sure our current file number is valid if (cur_file >= s->num_files) return 0; // Read a subint of data from the DATA col if (cur_subint <= s->num_subint[cur_file]) { double offs_sub = 0.0; if (!offs_sub_are_zero) { // Read the OFFS_SUB column value in case there were dropped blocks fits_read_col(s->fitsfiles[cur_file], TDOUBLE, s->offs_sub_col, cur_subint, 1L, 1L, 0, &offs_sub, &anynull, &status); // Set new_spec to proper value, accounting for possibly // missing initial rows of data and/or combining observations // Note: need to remove start_subint because that was already put // into start_spec. This is important if initial rows are gone. new_spec = s->start_spec[cur_file] + roundl((offs_sub - (s->start_subint[cur_file] + 0.5) * s->time_per_subint) / s->dt); } else { new_spec = s->start_spec[cur_file] + (cur_subint - 1) * s->spectra_per_subint; } //printf("cur/new_spec = %lld, %lld s->start_spec[cur_file] = %lld\n", // cur_spec, new_spec, s->start_spec[cur_file]); // The following determines if there were lost blocks, or if // we are putting different observations together so that // the blocks are not aligned if (new_spec == cur_spec + numbuffered) { // if things look good, with no missing blocks, read the data get_PSRFITS_subint(fdataptr, cdatabuffer, s); cur_subint++; goto return_block; } else { goto padding_block; } } else { // We are going to move to the next file, so update // new_spec to be the starting spectra from the next file // so we can see if any padding is necessary if (cur_file < s->num_files - 1) new_spec = s->start_spec[cur_file + 1]; else new_spec = cur_spec + numbuffered; } if (new_spec == cur_spec + numbuffered) { // No padding is necessary, so switch files cur_file++; cur_subint = 1; return get_PSRFITS_rawblock(fdata, s, padding); } else { // add padding goto padding_block; } padding_block: if (new_spec < cur_spec) { // Files out of order? Shouldn't get here. fprintf(stderr, "Error!: Current subint has earlier time than previous!\n\n" "\tfilename = '%s', subint = %d\n" "\tcur_spec = %lld new_spec = %lld\n", s->filenames[cur_file], cur_subint, cur_spec, new_spec); exit(1); } numtopad = new_spec - cur_spec; // Don't add more than 1 block and if buffered, then realign the buffer if (numtopad > (s->spectra_per_subint - numbuffered)) numtopad = s->spectra_per_subint - numbuffered; add_padding(fdataptr, s->padvals, s->num_channels, numtopad); // Update pointer into the buffer numbuffered = (numbuffered + numtopad) % s->spectra_per_subint; // Set the padding flag *padding = 1; // If we haven't gotten a full block, or completed the buffered one // then recursively call get_PSRFITS_rawblock() if (numbuffered) { printf("Adding %d spectra of padding to buffer at subint %d\n", numtopad, cur_subint); return get_PSRFITS_rawblock(fdata, s, padding); } else { printf("Adding %d spectra of padding at subint %d\n", numtopad, cur_subint); goto return_block; } return_block: // Apply the corrections that need a full block // Invert the band if needed if (s->apply_flipband) flip_band(fdata, s); // Perform Zero-DMing if requested if (s->remove_zerodm) remove_zerodm(fdata, s); // Increment our static counter (to determine how much data we // have written on the fly). cur_spec += s->spectra_per_subint; return 1; }
void domathl (void) { #ifndef NO_LONG_DOUBLE long double f1; long double f2; int i1; f1 = acosl(0.0); fprintf( stdout, "acosl : %Lf\n", f1); f1 = acoshl(0.0); fprintf( stdout, "acoshl : %Lf\n", f1); f1 = asinl(1.0); fprintf( stdout, "asinl : %Lf\n", f1); f1 = asinhl(1.0); fprintf( stdout, "asinhl : %Lf\n", f1); f1 = atanl(M_PI_4); fprintf( stdout, "atanl : %Lf\n", f1); f1 = atan2l(2.3, 2.3); fprintf( stdout, "atan2l : %Lf\n", f1); f1 = atanhl(1.0); fprintf( stdout, "atanhl : %Lf\n", f1); f1 = cbrtl(27.0); fprintf( stdout, "cbrtl : %Lf\n", f1); f1 = ceill(3.5); fprintf( stdout, "ceill : %Lf\n", f1); f1 = copysignl(3.5, -2.5); fprintf( stdout, "copysignl : %Lf\n", f1); f1 = cosl(M_PI_2); fprintf( stdout, "cosl : %Lf\n", f1); f1 = coshl(M_PI_2); fprintf( stdout, "coshl : %Lf\n", f1); f1 = erfl(42.0); fprintf( stdout, "erfl : %Lf\n", f1); f1 = erfcl(42.0); fprintf( stdout, "erfcl : %Lf\n", f1); f1 = expl(0.42); fprintf( stdout, "expl : %Lf\n", f1); f1 = exp2l(0.42); fprintf( stdout, "exp2l : %Lf\n", f1); f1 = expm1l(0.00042); fprintf( stdout, "expm1l : %Lf\n", f1); f1 = fabsl(-1.123); fprintf( stdout, "fabsl : %Lf\n", f1); f1 = fdiml(1.123, 2.123); fprintf( stdout, "fdiml : %Lf\n", f1); f1 = floorl(0.5); fprintf( stdout, "floorl : %Lf\n", f1); f1 = floorl(-0.5); fprintf( stdout, "floorl : %Lf\n", f1); f1 = fmal(2.1, 2.2, 3.01); fprintf( stdout, "fmal : %Lf\n", f1); f1 = fmaxl(-0.42, 0.42); fprintf( stdout, "fmaxl : %Lf\n", f1); f1 = fminl(-0.42, 0.42); fprintf( stdout, "fminl : %Lf\n", f1); f1 = fmodl(42.0, 3.0); fprintf( stdout, "fmodl : %Lf\n", f1); /* no type-specific variant */ i1 = fpclassify(1.0); fprintf( stdout, "fpclassify : %d\n", i1); f1 = frexpl(42.0, &i1); fprintf( stdout, "frexpl : %Lf\n", f1); f1 = hypotl(42.0, 42.0); fprintf( stdout, "hypotl : %Lf\n", f1); i1 = ilogbl(42.0); fprintf( stdout, "ilogbl : %d\n", i1); /* no type-specific variant */ i1 = isfinite(3.0); fprintf( stdout, "isfinite : %d\n", i1); /* no type-specific variant */ i1 = isgreater(3.0, 3.1); fprintf( stdout, "isgreater : %d\n", i1); /* no type-specific variant */ i1 = isgreaterequal(3.0, 3.1); fprintf( stdout, "isgreaterequal : %d\n", i1); /* no type-specific variant */ i1 = isinf(3.0); fprintf( stdout, "isinf : %d\n", i1); /* no type-specific variant */ i1 = isless(3.0, 3.1); fprintf( stdout, "isless : %d\n", i1); /* no type-specific variant */ i1 = islessequal(3.0, 3.1); fprintf( stdout, "islessequal : %d\n", i1); /* no type-specific variant */ i1 = islessgreater(3.0, 3.1); fprintf( stdout, "islessgreater : %d\n", i1); /* no type-specific variant */ i1 = isnan(0.0); fprintf( stdout, "isnan : %d\n", i1); /* no type-specific variant */ i1 = isnormal(3.0); fprintf( stdout, "isnormal : %d\n", i1); /* no type-specific variant */ f1 = isunordered(1.0, 2.0); fprintf( stdout, "isunordered : %d\n", i1); f1 = j0l(1.2); fprintf( stdout, "j0l : %Lf\n", f1); f1 = j1l(1.2); fprintf( stdout, "j1l : %Lf\n", f1); f1 = jnl(2,1.2); fprintf( stdout, "jnl : %Lf\n", f1); f1 = ldexpl(1.2,3); fprintf( stdout, "ldexpl : %Lf\n", f1); f1 = lgammal(42.0); fprintf( stdout, "lgammal : %Lf\n", f1); f1 = llrintl(-0.5); fprintf( stdout, "llrintl : %Lf\n", f1); f1 = llrintl(0.5); fprintf( stdout, "llrintl : %Lf\n", f1); f1 = llroundl(-0.5); fprintf( stdout, "lroundl : %Lf\n", f1); f1 = llroundl(0.5); fprintf( stdout, "lroundl : %Lf\n", f1); f1 = logl(42.0); fprintf( stdout, "logl : %Lf\n", f1); f1 = log10l(42.0); fprintf( stdout, "log10l : %Lf\n", f1); f1 = log1pl(42.0); fprintf( stdout, "log1pl : %Lf\n", f1); f1 = log2l(42.0); fprintf( stdout, "log2l : %Lf\n", f1); f1 = logbl(42.0); fprintf( stdout, "logbl : %Lf\n", f1); f1 = lrintl(-0.5); fprintf( stdout, "lrintl : %Lf\n", f1); f1 = lrintl(0.5); fprintf( stdout, "lrintl : %Lf\n", f1); f1 = lroundl(-0.5); fprintf( stdout, "lroundl : %Lf\n", f1); f1 = lroundl(0.5); fprintf( stdout, "lroundl : %Lf\n", f1); f1 = modfl(42.0,&f2); fprintf( stdout, "lmodfl : %Lf\n", f1); f1 = nanl(""); fprintf( stdout, "nanl : %Lf\n", f1); f1 = nearbyintl(1.5); fprintf( stdout, "nearbyintl : %Lf\n", f1); f1 = nextafterl(1.5,2.0); fprintf( stdout, "nextafterl : %Lf\n", f1); f1 = powl(3.01, 2.0); fprintf( stdout, "powl : %Lf\n", f1); f1 = remainderl(3.01,2.0); fprintf( stdout, "remainderl : %Lf\n", f1); f1 = remquol(29.0,3.0,&i1); fprintf( stdout, "remquol : %Lf\n", f1); f1 = rintl(0.5); fprintf( stdout, "rintl : %Lf\n", f1); f1 = rintl(-0.5); fprintf( stdout, "rintl : %Lf\n", f1); f1 = roundl(0.5); fprintf( stdout, "roundl : %Lf\n", f1); f1 = roundl(-0.5); fprintf( stdout, "roundl : %Lf\n", f1); f1 = scalblnl(1.2,3); fprintf( stdout, "scalblnl : %Lf\n", f1); f1 = scalbnl(1.2,3); fprintf( stdout, "scalbnl : %Lf\n", f1); /* no type-specific variant */ i1 = signbit(1.0); fprintf( stdout, "signbit : %i\n", i1); f1 = sinl(M_PI_4); fprintf( stdout, "sinl : %Lf\n", f1); f1 = sinhl(M_PI_4); fprintf( stdout, "sinhl : %Lf\n", f1); f1 = sqrtl(9.0); fprintf( stdout, "sqrtl : %Lf\n", f1); f1 = tanl(M_PI_4); fprintf( stdout, "tanl : %Lf\n", f1); f1 = tanhl(M_PI_4); fprintf( stdout, "tanhl : %Lf\n", f1); f1 = tgammal(2.1); fprintf( stdout, "tgammal : %Lf\n", f1); f1 = truncl(3.5); fprintf( stdout, "truncl : %Lf\n", f1); f1 = y0l(1.2); fprintf( stdout, "y0l : %Lf\n", f1); f1 = y1l(1.2); fprintf( stdout, "y1l : %Lf\n", f1); f1 = ynl(3,1.2); fprintf( stdout, "ynl : %Lf\n", f1); #endif }