Scales determineScaling(Function fun) { bool linear; bool sublinear; unsigned trial = 0; for (; trial < num_times; trial += 1) { if (trial > 0 && ((times[trial - 1] * sizes[trial]) > 10)) { break; } setA = &setsA[trial]; setB = &setsB[trial]; setAPrime = &setsAPrime[trial]; times[trial] = timeFunction(fun); printf("time taken for size %d was %g\n", sizes[trial], times[trial]); } if (trial < 3) { printf("I'm sorry, your program is way too inefficient.\n"); printf("you'll need to find a way-faster computer to test it on\n"); return SUPER_LINEAR; } linear = checkLinear(times, sizes, 0, trial - 1) || checkLinear(times, sizes, 1, trial - 1); sublinear = checkSubLinear(times, sizes, 0, trial - 1) || checkSubLinear(times, sizes, 1, trial - 1); if (sublinear) { return SUB_LINEAR; } else if (linear) { return LINEAR; } else { return SUPER_LINEAR; } }
void NetAndUart::init_connect() { //打开串口,根据参数,初始化串口 connect(open_button, SIGNAL(clicked()), this, SLOT(open_button_clicked())); connect(timerData, SIGNAL(timeout()), this, SLOT(timeFunction())); //网络相关接口 connect(hostLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableGetFortuneButton())); connect(portLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableGetFortuneButton())); connect(getFortuneButton, SIGNAL(clicked()), this, SLOT(requestNewFortune())); }
// Write time dependent data. void writeTimeGrid( const xdm::FileSystemPath& path ) { xdm::RefPtr< xdmGrid::UniformGrid > grid = build2DGrid(); xdm::RefPtr< xdmGrid::Time > time = xdm::const_pointer_cast< xdmGrid::Time >( grid->time() ); xdmf::XmfWriter writer; writer.open( path, xdm::Dataset::kCreate ); xdm::RefPtr< xdmGrid::Attribute > attr = grid->attributeByName( "attr" ); xdm::RefPtr< xdm::UniformDataItem > data = attr->dataItem(); xdm::RefPtr< xdm::TypedStructuredArray< double > > array = data->typedArray<double>(); for ( int step = 0; step < 5; ++step ) { time->setValue( static_cast< double >( step ) ); std::fill( array->begin(), array->end(), timeFunction( step ) ); writer.write( grid, step ); } writer.close(); }
main( int argc, char **argv ) { char *argPtr; flag functionArgument; uint8 functionCode; int8 operands, roundingMode, tininessMode; if ( argc <= 1 ) goto writeHelpMessage; functionArgument = FALSE; functionCode = 0; operands = 0; roundingMode = 0; tininessMode = 0; --argc; ++argv; while ( argc && ( argPtr = argv[ 0 ] ) ) { if ( argPtr[ 0 ] == '-' ) ++argPtr; if ( strcmp( argPtr, "help" ) == 0 ) { writeHelpMessage: fputs( "timesoftfloat [<option>...] <function>\n" " <option>: (* is default)\n" " -help --Write this message and exit.\n" " -nearesteven --Only time rounding to nearest/even.\n" " -tozero --Only time rounding to zero.\n" " -down --Only time rounding down.\n" " -up --Only time rounding up.\n" " -tininessbefore --Only time underflow tininess before rounding.\n" " -tininessafter --Only time underflow tininess after rounding.\n" " <function>:\n" " int32_to_<float> <float>_add <float>_eq\n" " <float>_to_int32 <float>_sub <float>_le\n" " <float>_to_int32_round_to_zero <float>_mul <float>_lt\n" " <float>_to_<float> <float>_div <float>_eq_signaling\n" " <float>_round_to_int <float>_rem <float>_le_quiet\n" " <float>_sqrt <float>_lt_quiet\n" " -all1 --All 1-operand functions.\n" " -all2 --All 2-operand functions.\n" " -all --All functions.\n" " <float>:\n" " float32 --Single precision.\n" " float64 --Double precision.\n", stdout ); return EXIT_SUCCESS; } else if ( ( strcmp( argPtr, "nearesteven" ) == 0 ) || ( strcmp( argPtr, "nearest_even" ) == 0 ) ) { roundingMode = ROUND_NEAREST_EVEN; } else if ( ( strcmp( argPtr, "tozero" ) == 0 ) || ( strcmp( argPtr, "to_zero" ) == 0 ) ) { roundingMode = ROUND_TO_ZERO; } else if ( strcmp( argPtr, "down" ) == 0 ) { roundingMode = ROUND_DOWN; } else if ( strcmp( argPtr, "up" ) == 0 ) { roundingMode = ROUND_UP; } else if ( strcmp( argPtr, "tininessbefore" ) == 0 ) { tininessMode = TININESS_BEFORE_ROUNDING; } else if ( strcmp( argPtr, "tininessafter" ) == 0 ) { tininessMode = TININESS_AFTER_ROUNDING; } else if ( strcmp( argPtr, "all1" ) == 0 ) { functionArgument = TRUE; functionCode = 0; operands = 1; } else if ( strcmp( argPtr, "all2" ) == 0 ) { functionArgument = TRUE; functionCode = 0; operands = 2; } else if ( strcmp( argPtr, "all" ) == 0 ) { functionArgument = TRUE; functionCode = 0; operands = 0; } else { for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode ) { if ( strcmp( argPtr, functions[ functionCode ].name ) == 0 ) { break; } } if ( functionCode == NUM_FUNCTIONS ) { fail( "Invalid option or function `%s'", argv[ 0 ] ); } functionArgument = TRUE; } --argc; ++argv; } if ( ! functionArgument ) fail( "Function argument required" ); if ( functionCode ) { timeFunction( functionCode, roundingMode, tininessMode ); } else if ( operands == 1 ) { for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode ) { if ( functions[ functionCode ].numInputs == 1 ) { timeFunction( functionCode, roundingMode, tininessMode ); } } } else if ( operands == 2 ) { for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode ) { if ( functions[ functionCode ].numInputs == 2 ) { timeFunction( functionCode, roundingMode, tininessMode ); } } } else { for ( functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode ) { timeFunction( functionCode, roundingMode, tininessMode ); } } return EXIT_SUCCESS; }