ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dvect14.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
11 // file fvar_fn.cpp
12 // math.h functions involving prevariables
13 #include "fvar.hpp"
14 #include <stdio.h>
15 
20 double sfabs(const double v1)
21  {
22  #define cutoff 0.001
23  #define cutoff2 0.000001
24  double a = 2./cutoff;
25  double b = 1./cutoff2;
26 
27  double return_value;
28  double tmp1 = v1;
29  double tmp = ::fabs(tmp1);
30  if (tmp > cutoff)
31  {
32  return_value=tmp;
33  }
34  else
35  {
36  double t2 = tmp * tmp;
37 
38  if (tmp1 >=0)
39  {
40  return_value=t2*(a-b*tmp1);
41  }
42  else
43  {
44  return_value=t2*(a+b*tmp1);
45  }
46  }
47  return(return_value);
48  }
49 
54 dvector sfabs(const dvector& t1)
55 {
56  int min = t1.indexmin();
57  int max = t1.indexmax();
58  dvector tmp(min, max);
59  double* ptmpi = tmp.get_v() + min;
60  double* pt1i = t1.get_v() + min;
61  for (int i = min; i <= max; ++i)
62  {
63  *ptmpi = sfabs(*pt1i);
64  ++pt1i;
65  ++ptmpi;
66  }
67  return tmp;
68 }
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
#define cutoff
df1_two_variable fabs(const df1_two_variable &x)
Definition: df12fun.cpp:891
#define cutoff2
double sfabs(const double v1)
Description not yet available.
Definition: dvect14.cpp:20
#define min(a, b)
Definition: cbivnorm.cpp:188
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
#define max(a, b)
Definition: cbivnorm.cpp:189
double *& get_v(void)
Definition: dvector.h:148