Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,51 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* Author: David Fournier | ||
* Copyright (c) 2008-2012 Regents of the University of California | ||
*/ | ||
/** | ||
\file | ||
Robust exponential functions for variable scalar objects. | ||
*/ | ||
#include <fvar.hpp> | ||
\file Robust exponential functions for variable scalar objects. | ||
/** | ||
Robust exponential function for variable argument > 60 or < -60. | ||
Prevents overflow and underflow for arguments outside of the domain | ||
of exp(). | ||
(Note: \f$e^{60} > 10^{26}\f$.) | ||
\param x dvariable exponent. | ||
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} | ||
x > 60 & e^{60}\frac{(1+2(x-60))}{1+x-60}\\ | ||
x < 60 & e^{-60}\frac{(1-x-60)}{1+2(-x-60)}\\ | ||
{\rm else} & e^x | ||
\end{array}\right.\f$ | ||
\ingroup misc | ||
*/ | ||
dvariable mfexp(const prevariable& x) | ||
{ | ||
double b=60; | ||
if (x<=b && x>=-b) | ||
{ | ||
return exp(x); | ||
} | ||
else if (x>b) | ||
{ | ||
return exp(b)*(1.+2.*(x-b))/(1.+x-b); | ||
} | ||
else | ||
{ | ||
return exp(-b)*(1.-x-b)/(1.+2.*(-x-b)); | ||
} | ||
} | ||
Author: David Fournier | ||
Copyright (c) 2008-2015 Regents of the University of California | ||
*/ | ||
#include <fvar.hpp> | ||
|
||
/** | ||
Robust exponential function for variable argument with user | ||
specified domain bound. | ||
Prevents overflow and underflow for arguments outside of the domain | ||
\param x dvariable exponent. | ||
\param b double user specified function domain bound. | ||
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} | ||
Robust exponential function for variable argument with user | ||
specified domain bound. | ||
Prevents overflow and underflow for arguments outside of the domain | ||
\param x dvariable exponent. | ||
\param b double user specified function domain bound. | ||
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} | ||
x > b & e^b\frac{(1+2(x-b))}{1+x-b}\\ | ||
x < b & e^{-b}\frac{(1-x-b)}{1+2(-x-b)}\\ | ||
{\rm else} & e^x | ||
\end{array}\right.\f$ | ||
\ingroup misc | ||
*/ | ||
\end{array}\right.\f$ | ||
\ingroup misc | ||
*/ | ||
dvariable mfexp(const prevariable& x, double b) | ||
{ | ||
if (x > b) | ||
{ | ||
return exp(b)*(1.+2.*(x-b))/(1.+x-b); | ||
} | ||
else if (x < -b) | ||
{ | ||
if (x<=b && x>=-b) | ||
{ | ||
return exp(x); | ||
} | ||
else if (x>b) | ||
{ | ||
return exp(b)*(1.+2.*(x-b))/(1.+x-b); | ||
} | ||
else | ||
{ | ||
return exp(-b)*(1.-x-b)/(1.+2.*(-x-b)); | ||
} | ||
return exp(-b)*(1.-x-b)/(1.+2.*(-x-b)); | ||
} | ||
return exp(x); | ||
} | ||
/** | ||
Robust exponential function for variable argument > 60 or < -60. | ||
Prevents overflow and underflow for arguments outside of the domain | ||
of exp(). | ||
(Note: \f$e^{60} > 10^{26}\f$.) | ||
\param x dvariable exponent. | ||
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} | ||
x > 60 & e^{60}\frac{(1+2(x-60))}{1+x-60}\\ | ||
x < 60 & e^{-60}\frac{(1-x-60)}{1+2(-x-60)}\\ | ||
{\rm else} & e^x | ||
\end{array}\right.\f$ | ||
\ingroup misc | ||
*/ | ||
dvariable mfexp(const prevariable& x) | ||
{ | ||
double b = 60; | ||
return mfexp(x, b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,52 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* Author: David Fournier | ||
* Copyright (c) 2008-2012 Regents of the University of California | ||
*/ | ||
/** | ||
* \file | ||
Robust exponential functions for constant scalar objects. | ||
*/ | ||
#include <fvar.hpp> | ||
\file Robust exponential functions for constant scalar objects. | ||
/** | ||
Robust exponential function for constant argument > 60 or < -60. | ||
Prevents overflow and underflow for arguments outside of the domain | ||
of exp(). | ||
(Note: \f$e^{60} > 10^{26}\f$.) | ||
\param x exponent. | ||
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} | ||
x > 60 & e^{60}\frac{(1+2(x-60))}{1+x-60}\\ | ||
x < 60 & e^{-60}\frac{(1-x-60)}{1+2(-x-60)}\\ | ||
{\rm else} & e^x | ||
\end{array}\right.\f$ | ||
\ingroup misc | ||
*/ | ||
double mfexp(double x) | ||
{ | ||
double b = 60; | ||
if (x<=b && x>=-b) | ||
{ | ||
return exp(x); | ||
} | ||
else if (x>b) | ||
{ | ||
return exp(b)*(1.+2.*(x-b))/(1.+x-b); | ||
} | ||
else | ||
{ | ||
return exp(-b)*(1.-x-b)/(1.+2.*(-x-b)); | ||
} | ||
} | ||
Author: David Fournier | ||
Copyright (c) 2008-2015 Regents of the University of California | ||
*/ | ||
#include <fvar.hpp> | ||
|
||
/** | ||
Robust exponential function for constant argument with user | ||
specified domain bound. | ||
Prevents overflow and underflow for arguments outside of the domain | ||
\param x exponent. | ||
\param b ouble user specified function domain bound. | ||
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} | ||
Robust exponential function for constant argument with user | ||
specified domain bound. | ||
Prevents overflow and underflow for arguments outside of the domain | ||
\param x exponent. | ||
\param b ouble user specified function domain bound. | ||
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} | ||
x > b & e^b\frac{(1+2(x-b))}{1+x-b}\\ | ||
x < b & e^{-b}\frac{(1-x-b)}{1+2(-x-b)}\\ | ||
{\rm else} & e^x | ||
\end{array}\right.\f$ | ||
\ingroup misc | ||
*/ | ||
double mfexp(double x,double b) | ||
\end{array}\right.\f$ | ||
\ingroup misc | ||
*/ | ||
double mfexp(double x, double b) | ||
{ | ||
if (x > b) | ||
{ | ||
return exp(b)*(1.+2.*(x-b))/(1.+x-b); | ||
} | ||
else if (x < -b) | ||
{ | ||
if (x<=b && x>=-b) | ||
{ | ||
return exp(x); | ||
} | ||
else if (x>b) | ||
{ | ||
return exp(b)*(1.+2.*(x-b))/(1.+x-b); | ||
} | ||
else | ||
{ | ||
return exp(-b)*(1.-x-b)/(1.+2.*(-x-b)); | ||
} | ||
return exp(-b)*(1.-x-b)/(1.+2.*(-x-b)); | ||
} | ||
return exp(x); | ||
} | ||
/** | ||
Robust exponential function for constant argument > 60 or < -60. | ||
Prevents overflow and underflow for arguments outside of the domain | ||
of exp(). | ||
(Note: \f$e^{60} > 10^{26}\f$.) | ||
\param x exponent. | ||
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} | ||
x > 60 & e^{60}\frac{(1+2(x-60))}{1+x-60}\\ | ||
x < 60 & e^{-60}\frac{(1-x-60)}{1+2(-x-60)}\\ | ||
{\rm else} & e^x | ||
\end{array}\right.\f$ | ||
\ingroup misc | ||
*/ | ||
double mfexp(double x) | ||
{ | ||
double b = 60; | ||
return mfexp(x, b); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters