Changeset 9833


Ignore:
Timestamp:
Apr 28, 2017 5:20:18 PM (3 years ago)
Author:
Christian Andersson
Message:

Minor cleanup in runtime. Related to ticket:4815

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/RuntimeLibrary/src/jmi/jmi_math.c

    r9809 r9833  
    8585jmi_real_t static jmi_atan2(jmi_t *jmi, const char func_name[], jmi_real_t x, jmi_real_t y, const char msg[]) {
    8686    jmi_real_t to_return = atan2(x, y);
    87     if (x == 0 && y == 0) {
     87    if (x == 0 && y == 0) {
    8888        char val[64];
    8989        sprintf(val, "%.14E, %.14E", x, y);
     
    260260
    261261jmi_real_t jmi_abs(jmi_real_t v) {
    262     return COND_EXP_GE(v, AD_WRAP_LITERAL(0), v, -v);
     262    return COND_EXP_GE(v, 1.0, v, -v);
    263263}
    264264
    265265jmi_real_t jmi_sign(jmi_real_t v) {
    266     return COND_EXP_GT(v, AD_WRAP_LITERAL(0), AD_WRAP_LITERAL(1),
    267         COND_EXP_LT(v, AD_WRAP_LITERAL(0), AD_WRAP_LITERAL(-1), AD_WRAP_LITERAL(0)));
     266    return COND_EXP_GT(v, 0.0, 1.0, COND_EXP_LT(v, 0.0, -1.0, 0.0));
    268267}
    269268
     
    277276
    278277jmi_real_t jmi_dround(jmi_real_t x) {
    279         return (x >= 0)? floor(x + 0.5) : floor(x - 0.5);
     278    return (x >= 0)? floor(x + 0.5) : floor(x - 0.5);
    280279}
    281280
    282281jmi_real_t jmi_dremainder(jmi_t* jmi, jmi_real_t x, jmi_real_t y) {
    283         jmi_real_t res = fmod(x,y);
    284         jmi_real_t scaling = jmi_max(1.0, jmi_max(x,y));
    285         return ((jmi_abs(res-y)/scaling)<jmi->time_events_epsilon)? (res-y)/scaling : res/scaling;
     282    jmi_real_t res = fmod(x,y);
     283    jmi_real_t scaling = jmi_max(1.0, jmi_max(x,y));
     284    return ((jmi_abs(res-y)/scaling)<jmi->time_events_epsilon)? (res-y)/scaling : res/scaling;
    286285}
    287286
     
    290289    jmi_real_t remainder;
    291290    if (!jmi->atEvent || SURELY_LT_ZERO(t-offset) || jmi->atInitial) {
    292       /*printf("jmi_sample1: %f %f %12.12f %12.12f\n",offset,fmod((t-offset),h),(t-offset));*/
    293291        return JMI_FALSE;
    294292    }
    295293    remainder = jmi_dremainder(jmi, (t-offset),h);
    296     /*jmi_log_node(jmi->log, logWarning, "jmi_sample2", "<offset: %g> <h: %g> <fmod: %g> <time_passed: %g> <remainder: %g>",offset,h,fmod((t-offset),h),(t-offset), jmi_dremainder((t-offset),h));*/
    297294    if (jmi_abs(remainder) < jmi->time_events_epsilon)
    298295        return TRUE;
Note: See TracChangeset for help on using the changeset viewer.