ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
dvect14.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 // file fvar_fn.cpp
00012 // math.h functions involving prevariables
00013 #include "fvar.hpp"
00014 #include <stdio.h>
00015 
00020 double sfabs(const double v1)
00021  {
00022    #define cutoff 0.001
00023    #define cutoff2 0.000001
00024    double a = 2./cutoff;
00025    double b = 1./cutoff2;
00026 
00027    double return_value;
00028    double tmp1 = v1;
00029    double tmp = ::fabs(tmp1);
00030    if (tmp > cutoff)
00031    {
00032         return_value=tmp;
00033    }
00034    else
00035    {
00036      double t2 = tmp * tmp;
00037 
00038      if (tmp1 >=0)
00039      {
00040        return_value=t2*(a-b*tmp1);
00041      }
00042      else
00043      {
00044        return_value=t2*(a+b*tmp1);
00045      }
00046    }
00047    return(return_value);
00048  }
00049 
00054 dvector sfabs(const dvector& t1)
00055   {
00056      dvector tmp(t1.indexmin(),t1.indexmax());
00057 
00058      for (int i=t1.indexmin(); i<=t1.indexmax(); i++)
00059      {
00060        tmp.elem(i)=sfabs(t1.elem(i));
00061      }
00062      return(tmp);
00063   }