void view_time(const view *V, double t, state *s) { int i = (int) floor(t); int j = (int) ceil(t); if (i < j) state_mix(s, V->list + mmod(i - 1, V->n), V->list + mmod(i + 0, V->n), V->list + mmod(i + 1, V->n), V->list + mmod(i + 2, V->n), t - i); else memcpy(s, V->list + mmod(i, V->n), sizeof (state)); }
BigInt *balance(BigInt *num) { //makes sure every entry in digits is a digit int length = num->length; int *digits = num->digits; int sign = num->sign; int i=0; int needs_repeating = 0; for(i=0; i<length-1;++i) { digits[i+1] += mdiv(digits[i], 10); digits[i] = mmod(digits[i], 10); } if (digits[length-1] >= 10) { int a = mdiv(digits[length-1], 10); int b = mmod(digits[length-1], 10); digits[length] = a; digits[length-1] = b; ++length; } if(digits[length-1]<0) { digits[length-1] *= -1; sign *= -1; //perform k*10^length - rest = (k-1)*10^length + 999..99 - rest + 1 digits[length-1] -= 1; for(i=0; i<length-1; ++i) { digits[i] = 9 - digits[i]; } digits[0] += 1; //may cause digits[0] to become unbalanced again needs_repeating = 1; } num->digits = digits; num->length = length; num->sign = sign; num->size = num->size; if (needs_repeating) {num = balance(num);} //won't have the same problem again if(!strcmp(toString(num), "0")) { num->sign = 0; } return num; //TODO add 0 }
main(void) { MINT a,b,q,r; MINIT(&a); MINIT(&b); MINIT(&q); MINIT(&r); while ((fputs("a: ",stdout), min(&a) != EOF) && (fputs("b: ",stdout), min(&b) != EOF)) { mdiv(&a,&b,&q,&r); mout(&a); putchar('\n'); mout(&b); putchar('\n'); mout(&q); putchar('\n'); mout(&r); putchar('\n'); mmod(&a,&b,&r); mout(&a); putchar('\n'); mout(&b); putchar('\n'); mout(&r); putchar('\n'); } exit(0); }
// static pascal OSStatus IGraphicsCarbon::MainEventHandler(EventHandlerCallRef pHandlerCall, EventRef pEvent, void* pGraphicsCarbon) { IGraphicsCarbon* _this = (IGraphicsCarbon*) pGraphicsCarbon; IGraphicsMac* pGraphicsMac = _this->mGraphicsMac; UInt32 eventClass = GetEventClass(pEvent); UInt32 eventKind = GetEventKind(pEvent); switch (eventClass) { case kEventClassKeyboard: { switch (eventKind) { case kEventRawKeyDown: { if (_this->mTextEntryView) return eventNotHandledErr; bool handle = true; int key; UInt32 k; GetEventParameter(pEvent, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &k); char c; GetEventParameter(pEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(char), NULL, &c); if (k == 49) key = KEY_SPACE; else if (k == 125) key = KEY_DOWNARROW; else if (k == 126) key = KEY_UPARROW; else if (k == 123) key = KEY_LEFTARROW; else if (k == 124) key = KEY_RIGHTARROW; else if (c >= '0' && c <= '9') key = KEY_DIGIT_0+c-'0'; else if (c >= 'A' && c <= 'Z') key = KEY_ALPHA_A+c-'A'; else if (c >= 'a' && c <= 'z') key = KEY_ALPHA_A+c-'a'; else handle = false; if(handle) handle = pGraphicsMac->OnKeyDown(_this->mPrevX, _this->mPrevY, key); if(handle) return noErr; else return eventNotHandledErr; } } } case kEventClassControl: { switch (eventKind) { case kEventControlDraw: { int gfxW = pGraphicsMac->Width(), gfxH = pGraphicsMac->Height(); IRECT r = GetRegionRect(pEvent, gfxW, gfxH); CGrafPtr port = 0; if (_this->mIsComposited) { GetEventParameter(pEvent, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(CGContextRef), 0, &(_this->mCGC)); CGContextTranslateCTM(_this->mCGC, 0, gfxH); CGContextScaleCTM(_this->mCGC, 1.0, -1.0); pGraphicsMac->Draw(&r); } else { GetEventParameter(pEvent, kEventParamGrafPort, typeGrafPtr, 0, sizeof(CGrafPtr), 0, &port); QDBeginCGContext(port, &(_this->mCGC)); //RgnHandle clipRegion = NewRgn(); //GetPortClipRegion(port, clipRegion); Rect portBounds; GetPortBounds(port, &portBounds); int offsetW = 0; int offsetH = -portBounds.top; //int offsetH = (portBounds.bottom - portBounds.top) - gfxH; // this almost works with AS, but clip rect seems wrong when previewing/breaks RTAS if ((portBounds.right - portBounds.left) >= gfxW) { offsetW = 0.5 * ((portBounds.right - portBounds.left) - gfxW); } CGContextTranslateCTM(_this->mCGC, portBounds.left + offsetW, offsetH); r = IRECT(0, 0, pGraphicsMac->Width(), pGraphicsMac->Height()); pGraphicsMac->Draw(&r); // Carbon non-composited will redraw everything, the IRECT passed here is the entire plugin-gui QDEndCGContext(port, &(_this->mCGC)); //DisposeRgn(clipRegion); } return noErr; } } break; } case kEventClassMouse: { HIPoint hp; GetEventParameter(pEvent, kEventParamWindowMouseLocation, typeHIPoint, 0, sizeof(HIPoint), 0, &hp); #ifdef RTAS_API // Header offset hp.x -= _this->GetLeftOffset(); hp.y -= _this->GetTopOffset(); Rect bounds; GetWindowBounds(_this->mWindow, kWindowTitleBarRgn, &bounds); // adjust x mouse coord if the gui is less wide than the window // int windowWidth = (bounds.right - bounds.left); // // if (windowWidth > pGraphicsMac->Width()) // { // hp.x -= (int) floor((windowWidth - pGraphicsMac->Width()) / 2.); // } // Title bar Y offset hp.y -= bounds.bottom - bounds.top; int x = (int) hp.x; int y = (int) hp.y; #else // NOT RTAS HIPointConvert(&hp, kHICoordSpaceWindow, _this->mWindow, kHICoordSpaceView, _this->mView); int x = (int) hp.x - 2; int y = (int) hp.y - 3; #endif UInt32 mods; GetEventParameter(pEvent, kEventParamKeyModifiers, typeUInt32, 0, sizeof(UInt32), 0, &mods); EventMouseButton button; GetEventParameter(pEvent, kEventParamMouseButton, typeMouseButton, 0, sizeof(EventMouseButton), 0, &button); if (button == kEventMouseButtonPrimary && (mods & cmdKey)) button = kEventMouseButtonSecondary; IMouseMod mmod(true, button == kEventMouseButtonSecondary, (mods & shiftKey), (mods & controlKey), (mods & optionKey)); switch (eventKind) { case kEventMouseDown: { if (_this->mTextEntryView) { #if !(USE_MLTE) HIViewRef view; HIViewGetViewForMouseEvent(_this->mView, pEvent, &view); if (view == _this->mTextEntryView) break; #endif _this->EndUserInput(true); } #ifdef RTAS_API // RTAS triple click if (mmod.L && mmod.R && mmod.C && (pGraphicsMac->GetParamIdxForPTAutomation(x, y) > -1)) { return CallNextEventHandler(pHandlerCall, pEvent); } #endif CallNextEventHandler(pHandlerCall, pEvent); UInt32 clickCount = 0; GetEventParameter(pEvent, kEventParamClickCount, typeUInt32, 0, sizeof(UInt32), 0, &clickCount); if (clickCount > 1) { pGraphicsMac->OnMouseDblClick(x, y, &mmod); } else { pGraphicsMac->OnMouseDown(x, y, &mmod); } return noErr; } case kEventMouseUp: { pGraphicsMac->OnMouseUp(x, y, &mmod); return noErr; } case kEventMouseMoved: { _this->mPrevX = x; _this->mPrevY = y; pGraphicsMac->OnMouseOver(x, y, &mmod); return noErr; } case kEventMouseDragged: { if (!_this->mTextEntryView) pGraphicsMac->OnMouseDrag(x, y, &mmod); return noErr; } case kEventMouseWheelMoved: { EventMouseWheelAxis axis; GetEventParameter(pEvent, kEventParamMouseWheelAxis, typeMouseWheelAxis, 0, sizeof(EventMouseWheelAxis), 0, &axis); if (axis == kEventMouseWheelAxisY) { int d; GetEventParameter(pEvent, kEventParamMouseWheelDelta, typeSInt32, 0, sizeof(SInt32), 0, &d); if (_this->mTextEntryView) _this->EndUserInput(false); pGraphicsMac->OnMouseWheel(x, y, &mmod, d); return noErr; } } } break; } case kEventClassWindow: { WindowRef window; if (GetEventParameter(pEvent, kEventParamDirectObject, typeWindowRef, NULL, sizeof (WindowRef), NULL, &window) != noErr) break; switch (eventKind) { case kEventWindowDeactivated: { if (_this->mTextEntryView) _this->EndUserInput(false); break; } } break; } } return eventNotHandledErr; }
static int mprimef(unsigned int *n, unsigned int *q, int k) { int i, j; unsigned int *t, *x, *y; // generate x t = mcopy(n); while (1) { for (i = 0; i < MLENGTH(t); i++) t[i] = rand(); x = mmod(t, n); if (!MZERO(x) && !MEQUAL(x, 1)) break; mfree(x); } mfree(t); // exponentiate y = mmodpow(x, q, n); // done? if (MEQUAL(y, 1)) { mfree(x); mfree(y); return 1; } j = 0; while (1) { // y = n - 1? t = msub(n, y); if (MEQUAL(t, 1)) { mfree(t); mfree(x); mfree(y); return 1; } mfree(t); if (++j == k) { mfree(x); mfree(y); return 0; } // y = (y ^ 2) mod n t = mmul(y, y); mfree(y); y = mmod(t, n); mfree(t); // y = 1? if (MEQUAL(y, 1)) { mfree(x); mfree(y); return 0; } } }
virtual void Load( OptionRowDefinition &defOut, CString sParam ) { ASSERT( sParam.size() ); if( sParam.CompareNoCase("NoteSkins")==0 ) { FillNoteSkins( defOut, sParam ); return; } else if( sParam.CompareNoCase("Steps")==0 ) { FillSteps( defOut, sParam, false ); return; } else if( sParam.CompareNoCase("StepsLocked")==0 ) { FillSteps( defOut, sParam, true ); return; } else if( sParam.CompareNoCase("Characters")==0 ) { FillCharacters( defOut, sParam ); return; } else if( sParam.CompareNoCase("Styles")==0 ) { FillStyles( defOut, sParam ); return; } else if( sParam.CompareNoCase("Groups")==0 ) { FillGroups( defOut, sParam ); return; } else if( sParam.CompareNoCase("Difficulties")==0 ) { FillDifficulties( defOut, sParam ); return; } else if( sParam.CompareNoCase("SongsInCurrentSongGroup")==0 ) { FillSongsInCurrentSongGroup( defOut, sParam ); return; } Init(); defOut.Init(); m_bUseModNameForIcon = true; defOut.name = sParam; Default.Load( -1, ParseCommands(ENTRY_DEFAULT(sParam)) ); /* Parse the basic configuration metric. */ Commands cmds = ParseCommands( ENTRY(sParam) ); if( cmds.v.size() < 1 ) RageException::Throw( "Parse error in ScreenOptionsMaster::%s", sParam.c_str() ); defOut.bOneChoiceForAllPlayers = false; const int NumCols = atoi( cmds.v[0].m_vsArgs[0] ); for( unsigned i=1; i<cmds.v.size(); i++ ) { const Command &cmd = cmds.v[i]; CString sName = cmd.GetName(); if( sName == "together" ) defOut.bOneChoiceForAllPlayers = true; else if( sName == "selectmultiple" ) defOut.selectType = SELECT_MULTIPLE; else if( sName == "selectone" ) defOut.selectType = SELECT_ONE; else if( sName == "selectnone" ) defOut.selectType = SELECT_NONE; else if( sName == "showoneinrow" ) defOut.layoutType = LAYOUT_SHOW_ONE_IN_ROW; else if( sName == "reloadrowmessages" ) { for( unsigned a=1; a<cmd.m_vsArgs.size(); a++ ) m_vsReloadRowMessages.push_back( cmd.m_vsArgs[a] ); } else if( sName == "enabledforplayers" ) { defOut.m_vEnabledForPlayers.clear(); for( unsigned a=1; a<cmd.m_vsArgs.size(); a++ ) { CString sArg = cmd.m_vsArgs[a]; PlayerNumber pn = (PlayerNumber)(atoi(sArg)-1); ASSERT( pn >= 0 && pn < NUM_PLAYERS ); defOut.m_vEnabledForPlayers.insert( pn ); } } else if( sName == "exportonchange" ) defOut.m_bExportOnChange = true; else if( sName == "broadcastonexport" ) { for( unsigned i=1; i<cmd.m_vsArgs.size(); i++ ) m_vsBroadcastOnExport.push_back( cmd.m_vsArgs[i] ); } else RageException::Throw( "Unkown row flag \"%s\"", sName.c_str() ); } for( int col = 0; col < NumCols; ++col ) { GameCommand mc; mc.Load( 0, ParseCommands(ENTRY_MODE(sParam, col)) ); /* If the row has just one entry, use the name of the row as the name of the * entry. If it has more than one, each one must be specified explicitly. */ if( mc.m_sName == "" && NumCols == 1 ) mc.m_sName = sParam; if( mc.m_sName == "" ) RageException::Throw( "List \"%s\", col %i has no name", sParam.c_str(), col ); if( !mc.IsPlayable() ) { LOG->Trace( "\"%s\" is not playable.", sParam.c_str() ); continue; } ListEntries.push_back( mc ); CString sName = mc.m_sName; CString sChoice = mc.m_sName; defOut.choices.push_back( sChoice ); } // OpenITG hack: load player-defined speed mods if (sParam == "Speed") { set<CString> additionalSet; // load anything from the machine profile first Profile *pMProf = PROFILEMAN->GetMachineProfile(); if (pMProf != NULL) { FOREACH_CONST(CString, pMProf->m_sPlayerAdditionalModifiers, mod) additionalSet.insert(*mod); } // then load anything from the players' profiles FOREACH_EnabledPlayer( pn ) { Profile *pProf = PROFILEMAN->GetProfile(pn); if (pProf == NULL) continue; FOREACH_CONST(CString, pProf->m_sPlayerAdditionalModifiers, mod) additionalSet.insert(*mod); } FOREACHS_CONST( CString, additionalSet, addit_mod ) { Regex mult("^[0-9]{1,2}(\\.[0-9]{1,2})?x$"); Regex constmod("^C[0-9]{1,4}$"); Regex mmod("^M[0-9]{1,4}$"); CString sAdditModName; if (mult.Compare(*addit_mod)) { float factor = 1.0f; sscanf(*addit_mod, "%fx", &factor); sAdditModName = ssprintf("x%.1f", factor); } else if (constmod.Compare(*addit_mod)) { unsigned bpm = 300; sscanf(*addit_mod, "C%u", &bpm); sAdditModName = ssprintf("c%u", bpm); } else if (mmod.Compare(*addit_mod)) { unsigned bpm = 600; sscanf(*addit_mod, "M%u", &bpm); sAdditModName = ssprintf("m%u", bpm); } else ASSERT(0); // how'd it get in here in the first place... GameCommand mc; mc.Load( 0, ParseCommands(CString("mod,")+*addit_mod+";name,"+sAdditModName) ); if ( !mc.IsPlayable() ) { LOG->Trace( "Additional mod \"%s\" is not playable.", addit_mod->c_str() ); continue; } ListEntries.push_back(mc); defOut.choices.push_back(mc.m_sName); }
int g (int *x) /*@*/ { (void) umod (x); (void) umod (mmod (umod (x))); return *x; }
int f (int *x) { (void) umod (mmod (umod (x))); return *x; }