static D jtremdd(J jt,D a,D b){D q,x,y; if(!a)R b; ASSERT(!INF(b),EVNAN); if(a==inf )R 0<=b?b:a; if(a==infm)R 0>=b?b:a; q=b/a; x=tfloor(q); y=tceil(q); R teq(x,y)?0:b-a*x; }
/** * Read the next token and interpret it as a constant. * Return its value. */ uint32_t tconst (void) { const char *t = tnext (); uint32_t i; /* If no value is given, default to 0. */ if (!t) return 0; /* Interpret certain fixed strings */ if (teq (t, "on") || teq (t, "high") || teq (t, "active")) return 1; if (teq (t, "off") || teq (t, "low") || teq (t, "inactive")) return 0; /* Dollar sign indicates a variable expansion */ if (*t == '$') { if (isdigit (t[1])) return conf_read_stack (t[1] - '0'); else return conf_read (t+1); } /* TODO : Builtin strings */ /* Anything else is interpreted as a C-formatted number. */ i = strtoul (t, NULL, 0); /* Optional modifiers that can occur after the number */ t = tnext (); if (t) { if (teq (t, "ms")) ; else if (teq (t, "secs")) i *= 1000; else tunget (t); } return i; }
void cRendererGLES2::ClipPlane( GLenum plane, const GLdouble * equation ) { Int32 nplane = plane - GL_CLIP_PLANE0; Int32 location; if ( nplane < EE_MAX_PLANES ) { location = mPlanes[ nplane ]; } else { std::string planeNum( "dgl_ClipPlane[" + String::ToStr( nplane ) + "]" ); location = glGetUniformLocation( mCurShader->Handler(), (GLchar*)&planeNum[0] ); } glm::vec4 teq( equation[0], equation[1], equation[2], equation[3] ); teq = teq * glm::inverse( mStack->mModelViewMatrix.top() ); /// Apply the inverse of the model view matrix to the equation glUniform4f( location, (GLfloat)teq[0], (GLfloat)teq[1], (GLfloat)teq[2], (GLfloat)teq[3] ); }
/* Constant time select from pre-computed table */ static void ECP8_ZZZ_select(ECP8_ZZZ *P,ECP8_ZZZ W[],sign32 b) { ECP8_ZZZ MP; sign32 m=b>>31; sign32 babs=(b^m)-m; babs=(babs-1)/2; ECP8_ZZZ_cmove(P,&W[0],teq(babs,0)); // conditional move ECP8_ZZZ_cmove(P,&W[1],teq(babs,1)); ECP8_ZZZ_cmove(P,&W[2],teq(babs,2)); ECP8_ZZZ_cmove(P,&W[3],teq(babs,3)); ECP8_ZZZ_cmove(P,&W[4],teq(babs,4)); ECP8_ZZZ_cmove(P,&W[5],teq(babs,5)); ECP8_ZZZ_cmove(P,&W[6],teq(babs,6)); ECP8_ZZZ_cmove(P,&W[7],teq(babs,7)); ECP8_ZZZ_copy(&MP,P); ECP8_ZZZ_neg(&MP); // minus P ECP8_ZZZ_cmove(P,&MP,(int)(m&1)); }
int main (void) { int j; mpfr_t x; tests_start_mpfr (); special (); mpfr_init2 (x, 500); for (j = 0; j < 500; j++) { mpfr_urandomb (x, RANDS); teq (x); } mpfr_clear (x); tests_end_mpfr (); return 0; }
/** * Read the next token, which must be a signal name. * Currently, this must be the last token in the command. * The general format is <type> <number>. */ uint32_t tsigno (void) { const char *t = tnext (); uint32_t signo; if (teq (t, "sol")) signo = SIGNO_SOL; else if (teq (t, "zerocross")) signo = SIGNO_ZEROCROSS; else if (teq (t, "triac")) signo = SIGNO_TRIAC; else if (teq (t, "lamp")) signo = SIGNO_LAMP; else if (teq (t, "sol_voltage")) signo = SIGNO_SOL_VOLTAGE; else if (teq (t, "ac_angle")) signo = SIGNO_AC_ANGLE; else return 0; signo += tconst (); return signo; }
/** * Parse and execute a script command. */ void exec_script (char *cmd) { const char *t; uint32_t v, count; tlast = NULL; /* Blank lines and comments are ignored */ t = tfirst (cmd); if (!t) return; if (*t == '#') return; /*********** capture [subcommand] [args...] ***************/ if (teq (t, "capture")) { struct signal_expression *ex; t = tnext (); if (teq (t, "start")) { ex = texpr (); signal_capture_start (ex); } else if (teq (t, "stop")) { ex = texpr (); signal_capture_stop (ex); } else if (teq (t, "debug")) { } else if (teq (t, "file")) { t = tnext (); signal_capture_set_file (t); } else if (teq (t, "add")) { signal_capture_add (tsigno ()); } else if (teq (t, "del")) { signal_capture_del (tsigno ()); } } /*********** set [var] [value] ***************/ else if (teq (t, "set")) { t = tnext (); v = tconst (); conf_write (t, v); } /*********** p/print [var] ***************/ else if (teq (t, "p") || teq (t, "print")) { v = tconst (); simlog (SLC_DEBUG, "%d", v); } /*********** include [filename] ***************/ else if (teq (t, "include")) { t = tnext (); exec_script_file (t); } /*********** sw [id] ***************/ else if (teq (t, "sw")) { v = tsw (); count = tconst (); if (count == 0) count = 1; while (count > 0) { sim_switch_depress (v); count--; } } /*********** swtoggle [id] ***************/ else if (teq (t, "swtoggle")) { v = tsw (); count = tconst (); if (count == 0) count = 1; while (count > 0) { sim_switch_toggle (v); count--; } } /*********** key [keyname] [switch] ***************/ else if (teq (t, "key")) { t = tnext (); v = tsw (); simlog (SLC_DEBUG, "Key '%c' = %s", *t, names_of_switches[v]); sim_key_install (*t, v); } /*********** push [value] ***************/ else if (teq (t, "push")) { v = tconst (); conf_push (v); } /*********** pop [argcount] ***************/ else if (teq (t, "pop")) { v = tconst (); conf_pop (v); } /*********** sleep [time] ***************/ else if (teq (t, "sleep")) { v = tconst (); simlog (SLC_DEBUG, "Sleeping for %d ms", v); v /= IRQS_PER_TICK; do { task_sleep (TIME_16MS); } while (--v > 0); simlog (SLC_DEBUG, "Awake again.", v); } /*********** exit ***************/ else if (teq (t, "exit")) { sim_exit (0); } }
/** * Parse a complex expression and return a * signal_expression that describes it. */ struct signal_expression *texpr (void) { struct signal_expression *ex, *ex1, *ex2; const char *t; t = tnext (); if (!t) return NULL; ex = expr_alloc (); if (teq (t, "at")) { ex->op = SIG_TIME; ex->u.timer = tconst (); } else if (teq (t, "after")) { ex->op = SIG_TIMEDIFF; ex->u.timer = tconst (); } else { tunget (t); ex->op = SIG_SIGNO; ex->u.signo = tsigno (); simlog (SLC_DEBUG, "Signo changed = 0x%X\n", ex->u.signo); t = tnext (); if (t) { if (teq (t, "is")) { ex1 = ex; ex2 = expr_alloc (); ex2->op = SIG_CONST; ex2->u.value = tconst (); ex = expr_alloc (); ex->op = SIG_EQ; ex->u.binary.left = ex1; ex->u.binary.right = ex2; } } } t = tnext (); if (t) { ex1 = ex; ex2 = texpr (); ex = expr_alloc (); ex->u.binary.left = ex1; ex->u.binary.right = ex2; if (teq (t, "and")) ex->op = SIG_AND; else if (teq (t, "or")) ex->op = SIG_OR; } return ex; }