Changeset 179 for trunk/ADOL-C/src


Ignore:
Timestamp:
Oct 14, 2010 2:48:01 AM (10 years ago)
Author:
kulshres
Message:

Correct bug in tapeless adouble log and sqrt functions

Reported-by: Schlenkrich Sebastian <Sebastian.Schlenkrich@…>
Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ADOL-C/src/adouble.h

    r168 r179  
    469469#else
    470470
     471#include <limits>
     472
    471473namespace adtl {
    472474
     
    506508
    507509inline double makeNaN() {
    508 #if defined(non_num)
    509     double a,b;
    510     a=non_num;
    511     b=non_den;
    512     return a/b;
    513 #else
    514 #  error Error: non_num undefined!
    515 #endif
     510    return ADOLC_MATH_NSP::numeric_limits<double>::quiet_NaN();
     511}
     512
     513inline double makeInf() {
     514    return ADOLC_MATH_NSP::numeric_limits<double>::infinity();
    516515}
    517516
     
    866865    tmp.val=ADOLC_MATH_NSP::log(a.val);
    867866    FOR_I_EQ_0_LT_NUMDIR
    868       if ((a.val>0 || a.val==0) && a.ADVAL_I>=0) tmp.ADVAL_I=a.ADVAL_I/a.val;
    869     else tmp.ADVAL_I=makeNaN();
     867        if (a.val>0) tmp.ADVAL_I=a.ADVAL_I/a.val;
     868        else if (a.val==0 && a.ADVAL_I != 0.0) {
     869            int sign = (a.ADVAL_I < 0)  ? -1 : 1;
     870            tmp.ADVAL_I=sign*makeInf();
     871        } else tmp.ADVAL_I=makeNaN();
    870872    return tmp;
    871873}
     
    875877    tmp.val=ADOLC_MATH_NSP::sqrt(a.val);
    876878    FOR_I_EQ_0_LT_NUMDIR
    877       if ((a.val>0 || a.val==0) && a.ADVAL_I>=0) tmp.ADVAL_I=a.ADVAL_I/tmp.val/2;
    878     else tmp.ADVAL_I=makeNaN();
     879        if (a.val>0) tmp.ADVAL_I=a.ADVAL_I/(tmp.val*2);
     880        else if (a.val==0.0 && a.ADVAL_I != 0.0) {
     881            int sign = (a.ADVAL_I < 0) ? -1 : 1;
     882            tmp.ADVAL_I=sign * makeInf();
     883        } else tmp.ADVAL_I=makeNaN();
    879884    return tmp;
    880885}
Note: See TracChangeset for help on using the changeset viewer.