void test_lround() { static_assert((std::is_same<decltype(lround((double)0)), long>::value), ""); static_assert((std::is_same<decltype(lroundf(0)), long>::value), ""); static_assert((std::is_same<decltype(lroundl(0)), long>::value), ""); assert(lround(1) == 1L); }
TEST(math, lround) { auto guard = make_scope_guard([]() { fesetenv(FE_DFL_ENV); }); fesetround(FE_UPWARD); // lround ignores the rounding mode. ASSERT_EQ(1234, lround(1234.01)); ASSERT_EQ(1234, lroundf(1234.01f)); ASSERT_EQ(1234, lroundl(1234.01L)); }
void testl(long double x) { #ifdef HAVE_C99_RUNTIME if (sizeof(long) != sizeof(long long)) return; if (lroundl(x) != llroundl(x)) link_error(); if (lrintl(x) != llrintl(x)) link_error(); #endif }
void testl(long double x) { #ifdef HAVE_C99_RUNTIME if (sizeof(long) != sizeof(long long)) return; if (__builtin_lceill(x) != __builtin_llceill(x)) link_error(); if (__builtin_lfloorl(x) != __builtin_llfloorl(x)) link_error(); if (lroundl(x) != llroundl(x)) link_error(); if (lrintl(x) != llrintl(x)) link_error(); #endif }
int main(void) { long double NaN = 0.0l / 0.0l; long double Inf = 1.0l / 0.0l; long double negInf = -1.0l / 0.0l; long double a = -1.5l; long double b = -1.49999999999999999l; long double c = 3.5l; long double d = 2.0l; assert(lroundl(a) == -2); assert(lroundl(b) == 1); assert(lroundl(c) == 4); assert(lroundl(d) == 2); assert(lroundl(0.0l) == 0); assert(lroundl(-0.0l) == 0); int isNeg = __signbitl(lroundl(-0.0l)); assert(isNeg); return 0; }
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 }
int main(int argc, char *argv[]) { long double x; x = lroundl((long double) argc); return 0; }
TEST(math, lround) { fesetround(FE_UPWARD); // lround ignores the rounding mode. ASSERT_EQ(1234, lround(1234.01)); ASSERT_EQ(1234, lroundf(1234.01f)); ASSERT_EQ(1234, lroundl(1234.01)); }
static int testl(long double long_double_x, int int_x, long long_x) { int r = 0; r += __finitel(long_double_x); r += __fpclassifyl(long_double_x); r += __isinfl(long_double_x); r += __isnanl(long_double_x); r += __signbitl(long_double_x); r += acoshl(long_double_x); r += acosl(long_double_x); r += asinhl(long_double_x); r += asinl(long_double_x); r += atan2l(long_double_x, long_double_x); r += atanhl(long_double_x); r += atanl(long_double_x); r += cbrtl(long_double_x); r += ceill(long_double_x); r += copysignl(long_double_x, long_double_x); r += coshl(long_double_x); r += cosl(long_double_x); r += erfcl(long_double_x); r += erfl(long_double_x); r += exp2l(long_double_x); r += expl(long_double_x); r += expm1l(long_double_x); r += fabsl(long_double_x); r += fdiml(long_double_x, long_double_x); r += floorl(long_double_x); r += fmal(long_double_x, long_double_x, long_double_x); r += fmaxl(long_double_x, long_double_x); r += fminl(long_double_x, long_double_x); r += fmodl(long_double_x, long_double_x); r += frexpl(long_double_x, &int_x); r += hypotl(long_double_x, long_double_x); r += ilogbl(long_double_x); r += ldexpl(long_double_x, int_x); r += lgammal(long_double_x); r += llrintl(long_double_x); r += llroundl(long_double_x); r += log10l(long_double_x); r += log1pl(long_double_x); r += log2l(long_double_x); r += logbl(long_double_x); r += logl(long_double_x); r += lrintl(long_double_x); r += lroundl(long_double_x); r += modfl(long_double_x, &long_double_x); r += nearbyintl(long_double_x); r += nextafterl(long_double_x, long_double_x); r += nexttowardl(long_double_x, long_double_x); r += powl(long_double_x, long_double_x); r += remainderl(long_double_x, long_double_x); r += remquol(long_double_x, long_double_x, &int_x); r += rintl(long_double_x); r += roundl(long_double_x); r += scalblnl(long_double_x, long_x); r += scalbnl(long_double_x, int_x); r += sinhl(long_double_x); r += sinl(long_double_x); r += sqrtl(long_double_x); r += tanhl(long_double_x); r += tanl(long_double_x); r += tgammal(long_double_x); r += truncl(long_double_x); return r; }
Error Cut(QList<QPolygonF> cuts, double mediawidth, double mediaheight, int media, int speed, int pressure, bool trackenhancing, bool regmark, bool regsearch, double regwidth, double reglength) { VENDOR_ID = ProgramOptions::Instance().getVendorUSB_ID(); PRODUCT_ID = ProgramOptions::Instance().getProductUSB_ID(); cout << "Cutting... VENDOR_ID : " << VENDOR_ID << " PRODUCT_ID: " << PRODUCT_ID << " mediawidth: " << mediawidth << " mediaheight: " << mediaheight << "media: " << media << " speed: " << speed << " pressure: " << pressure << " trackenhancing: " << trackenhancing << " regmark: " << regmark << " regsearch:" << regsearch <<" regwidth:" << regwidth << " reglength: " << reglength << endl; if (media < 100 || media > 300) media = 300; if (speed < 1) speed = 1; if (speed > 10) speed = 10; if (pressure < 1) pressure = 1; if (pressure > 33) pressure = 33; // how can VENDOR_ID / PRODUCT_ID report the correct values abve??? struct cutter_id id = { "?", 0, 0 }; libusb_device_handle* handle = UsbInit(&id); if (id.usb_vendor_id == VENDOR_ID_GRAPHTEC && id.usb_product_id == PRODUCT_ID_SILHOUETTE_CAMEO) { // should this also transform the regwidth regheigth or not? cuts = Transform_Silhouette_Cameo(cuts, &mediawidth, &mediaheight); } // TODO: Use exceptions. Error e = Success; string resp; // Initialise plotter. e = UsbSend(handle, "\x1b\x04"); if (!e) goto error; // Status request. e = UsbSend(handle, "\x1b\x05"); if (!e) goto error; e = UsbReceive(handle, resp, 5000); if (!e) goto error; if (resp != "0\x03") // 0 = Ready. 1 = Moving. 2 = Nothing loaded. " " = ?? { if (resp == "1\x03") e = Error("Moving, please try again."); else if (resp == "2\x03") e = Error("Empty tray, please load media."); // Silhouette Cameo else e = Error("Invalid response from plotter: " + resp); goto error; } // Home the cutter. e = UsbSend(handle, "TT\x03"); if (!e) goto error; // Query version. e = UsbSend(handle, "FG\x03"); if (!e) goto error; // Receive the firmware version. e = UsbReceive(handle, resp, 10000); // Large timeout because the plotter moves. if (!e) goto error; // Don't really care about this. // if (resp.length() != 10) // { // e = Error("Version error: " + version); // goto error; // } e = UsbSend(handle, "FW" + ItoS(media) + "\x03"); if (!e) goto error; e = UsbSend(handle, "!" + ItoS(speed) + "\x03"); if (!e) goto error; e = UsbSend(handle, "FX" + ItoS(pressure) + "\x03"); if (!e) goto error; // I think this sets the distance from the position of the plotter // head to the actual cutting point, maybe in 0.1 mms (todo: Measure blade). // It is 0 for the pen, 18 for cutting. // C possible stands for curvature. Not that any of the other letters make sense... e = UsbSend(handle, "FC" + ItoS(media == 113 ? 0 : 18) + "\x03"); if (!e) goto error; e = UsbSend(handle, "FY" + ItoS(trackenhancing ? 0 : 1) + "\x03"); if (!e) goto error; // Set to portrait. FN1 does landscape but it's easier just to rotate the image. e = UsbSend(handle, "FN0\x03"); if (!e) goto error; e = UsbSend(handle, "FE0\x03"); // No idea what this does. if (!e) goto error; e = UsbSend(handle, "TB71\x03"); // Again, no idea. Maybe something to do with registration marks? if (!e) goto error; e = UsbReceive(handle, resp, 10000); // Allow 10s. Seems reasonable. if (!e) goto error; if (resp != " 0, 0\x03") { e = Error("Invalid response from plotter."); goto error; } // Begin page definition. e = UsbSend(handle, "FA\x03"); if (!e) goto error; // Block for all the "jump to error crosses initialization" errors. Really need to use exceptions! { // Page size: height,width in 20ths of a mm minus a margin. This is for A4. TODO: Find maximum and use that. stringstream page; int width = lroundl(mediawidth * 20.0); int height = lroundl(mediaheight * 20.0); int margintop = ProgramOptions::Instance().getMarginTop(); int marginright = ProgramOptions::Instance().getMarginRight(); e = UsbSend(handle, "FU" + ItoS(height - margintop) + "," + ItoS(width - marginright) + "\x03"); if (!e) goto error; e = UsbSend(handle, "FM1\x03"); // ? if (!e) goto error; if (regmark) { stringstream regmarkstr; regmarkstr.precision(0); string searchregchar = "23,"; int regw = lroundl(regwidth * 20.0); int regl = lroundl(reglength * 20.0); e = UsbSend(handle, "TB50,381\x03"); //only with registration (it was TB50,1) ??? if (!e) goto error; if (regsearch) searchregchar ="123,"; regmarkstr << "TB99\x03TB55,1\x03TB" + searchregchar + ItoS(regw) + "," + ItoS(regl) + "\x03"; cout << "Registration mark string: " << regmarkstr.str() << endl; e = UsbSend(handle, regmarkstr.str()); //registration mark test /1-2: 180.0mm / 1-3: 230.0mm (origin 15mmx20mm) if (!e) goto error; e = UsbSend(handle, "FQ5\x03"); // only with registration ??? if (!e) goto error; e = UsbReceive(handle, resp, 40000); // Allow 20s for reply... if (!e) goto error; if (resp != " 0, 0\x03") { cout << resp << endl; e = Error("Couldn't find registration marks."); goto error; } // Looks like if the reg marks work it gets 3 messages back (if it fails it times out because it only gets the first message) e = UsbReceive(handle, resp, 40000); // Allow 20s for reply... if (!e) goto error; if (resp != " 0\x03") { cout << resp << endl; e = Error("Couldn't find registration marks."); goto error; } e = UsbReceive(handle, resp, 40000); // Allow 20s for reply... if (!e) goto error; if (resp != " 1\x03") { cout << resp << endl; e = Error("Couldn't find registration marks."); goto error; } } else { e = UsbSend(handle, "TB50,1\x03"); // ??? if (!e) goto error; } if (!e) goto error; // I think this is the feed command. Sometimes it is 5588 - maybe a maximum? e = UsbSend(handle, "FO" + ItoS(height - margintop) + "\x03"); if (!e) goto error; page.flags(ios::fixed); page.precision(0); page << "&100,100,100,\\0,0,Z" << ItoS(width) << "," << ItoS(height) << ",L0"; for (int i = 0; i < cuts.size(); ++i) { if (cuts[i].size() < 2) continue; double x = cuts[i][0].x()*20.0; double y = cuts[i][0].y()*20.0; double xorigin = ProgramOptions::Instance().getRegOriginWidthMM(); double yorigin = ProgramOptions::Instance().getRegOriginHeightMM(); if (regmark) { x = x - (xorigin*20.0); y = y + (yorigin*20.0); } // TODO: Also do this in the UI and warn the user about it. if (x < 0.0) x = 0.0; if (x > width) x = width; if (y < 0.0) y = 0.0; if (y > height) y = height; page << ",M" << x << "," << height-y; for (int j = 1; j < cuts[i].size(); ++j) { x = cuts[i][j].x()*20.0; y = cuts[i][j].y()*20.0; if (regmark) { x = x - (xorigin*20.0); y = y + (yorigin*20.0); } bool draw = true; if (x <= 0.0) { x = 0.0; draw = false; } if (x >= width) { x = width; draw = false; } if (y <= 0.0) { y = 0.0; draw = false; } if (y >= height) { y = height; draw = false; } if (draw) page << ",D" << x << "," << height-y; else page << ",M" << x << "," << height-y; // if outside the range just move } } page << "&1,1,1,TB50,0\x03"; // TB maybe .. ah I dunno. Need to experiment. No idea what &1,1,1 does either. // cout << page.str() << endl; e = UsbSend(handle, page.str()); if (!e) goto error; } // Feed the page out. e = UsbSend(handle, "FO0\x03"); if (!e) goto error; // Halt? e = UsbSend(handle, "H,"); if (!e) goto error; // Don't really care about the results of these! libusb_release_interface(handle, 0); libusb_close(handle); return Success; error: // Hey, this is basically C and I can't be bothered to properly C++-ify it. TODO: Use exceptions. cout << "Error: " << e << endl; libusb_release_interface(handle, 0); libusb_close(handle); return e; }