C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
rmath.inl
00001 /*
00002 **  CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
00003 **
00004 **  Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
00005 **                          Universitaet Karlsruhe, Germany
00006 **            (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
00007 **                          Universitaet Wuppertal, Germany   
00008 **
00009 **  This library is free software; you can redistribute it and/or
00010 **  modify it under the terms of the GNU Library General Public
00011 **  License as published by the Free Software Foundation; either
00012 **  version 2 of the License, or (at your option) any later version.
00013 **
00014 **  This library is distributed in the hope that it will be useful,
00015 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 **  Library General Public License for more details.
00018 **
00019 **  You should have received a copy of the GNU Library General Public
00020 **  License along with this library; if not, write to the Free
00021 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 /* CVS $Id: rmath.inl,v 1.31 2014/01/30 17:23:48 cxsc Exp $ */
00025 
00026 #include "rtsrmath.h"
00027 #include "xscclass.hpp"
00028 #define CXSC_INCLUDE
00029 #undef LINT_ARGS
00030 #include <fi_lib.hpp>
00031 #undef CXSC_INCLUDE
00032 
00033 //#include "fi_lib.hpp"
00034 
00035 namespace cxsc{
00036 using namespace fi_lib;
00037 inline real t_std_fct_call(int (fct)(const ExtReal *,ExtReal *),const real &arg)
00038 {
00039    real erg(arg);
00040    int rnd=t_grnd();
00041    t_srnd(NEAR);
00042    ExtReal a,r;
00043    t_ltoe((LongReal*)&erg,&a);
00044    fct(&a,&r);
00045    t_etol(&r,(LongReal*)&erg);
00046    t_srnd(rnd);
00047    return erg;
00048 }
00049 
00050 inline real t_std_fct_call(int (fct)(const ExtReal *,const ExtReal *,ExtReal *),const real & arg1, const real & arg2)
00051 {
00052    real erg(arg1),expo(arg2); // expo semioptimal.. :I
00053    int rnd=t_grnd();
00054    t_srnd(NEAR);
00055    ExtReal a,b,r;
00056    t_ltoe((LongReal*)&erg,&a);
00057    t_ltoe((LongReal*)&expo,&b);
00058    fct(&a,&b,&r);
00059    t_etol(&r,(LongReal*)&erg);
00060    t_srnd(rnd);
00061    return erg;
00062 }
00063 
00064 inline real sqr(const real &arg) throw() { return (arg*arg); }
00065 inline real sqrt(const real & arg)       { return q_sqrt(*(double *)&arg); } 
00066 // { return t_std_fct_call(t_sqte,arg); }
00067 inline real sqrt(const real & arg,int n) { return pow(arg,1.0/n); }
00068 // inline real sqrtm1(const real & arg)     { return t_std_fct_call(t_sqme,arg); }
00069 inline real sqrtm1(const real & arg) { 
00070    real erg(arg);
00071    int rnd=t_grnd();
00072    t_srnd(NEAR);
00073    ExtReal a,r;
00074    t_ltoe((LongReal*)&erg,&a);
00075    t_sqme(&a,&r);
00076    t_etol(&r,(LongReal*)&erg);
00077    t_srnd(rnd);
00078    return erg;
00079 }
00080 
00081 inline real sin(const real & arg) throw() { return q_sin(*(double*)&arg); } // { return t_std_fct_call(t_sine,arg); }
00082 inline real cos(const real & arg) throw() { return q_cos(*(double*)&arg); } // { return t_std_fct_call(t_cose,arg); }
00083 inline real tan(const real & arg) throw() { return q_tan(*(double*)&arg); } //{ return t_std_fct_call(t_tane,arg); }
00084 inline real cot(const real & arg) throw() { return q_cot(*(double*)&arg); } //{ return t_std_fct_call(t_cote,arg); }
00085 
00086 inline real asin(const real & arg)       { return q_asin(*(double*)&arg); } // { return t_std_fct_call(t_asne,arg); }
00087 inline real acos(const real & arg)       { return q_acos(*(double*)&arg); } // { return t_std_fct_call(t_acse,arg); }
00088 inline real atan(const real & arg)       { return q_atan(*(double*)&arg); } // { return t_std_fct_call(t_atne,arg); }
00089 inline real acot(const real & arg)       { return q_acot(*(double*)&arg); } // { return t_std_fct_call(t_acte,arg); }
00090 
00091 inline real expm1(const real & arg)throw() { return q_expm(*(double*)&arg); } // { return t_std_fct_call(t_exme,arg); }
00092 inline real lnp1(const real & arg)       { return q_lg1p(*(double*)&arg); } // { return t_std_fct_call(t_lnpe,arg); }
00093 
00094 inline real exp(const real & arg) throw() { return q_exp(*(double*)&arg); } // { return t_std_fct_call(t_expe,arg); }
00095 inline real ln(const real & arg)         { return q_log(*(double*)&arg); } // { return t_std_fct_call(t_lnee,arg); }
00096 inline real log2(const real & arg)       { return q_log2(*(double*)&arg); } // { return t_std_fct_call(t_lnee,arg); }
00097 inline real log10(const real & arg)      { return q_lg10(*(double*)&arg); } // { return t_std_fct_call(t_lnee,arg); }
00098 
00099 inline real sinh(const real & arg) throw() { return q_sinh(*(double*)&arg); } // { return t_std_fct_call(t_snhe,arg); }
00100 inline real cosh(const real & arg) throw() { return q_cosh(*(double*)&arg); } // { return t_std_fct_call(t_cshe,arg); }
00101 inline real tanh(const real & arg) throw() { return q_tanh(*(double*)&arg); } // { return t_std_fct_call(t_tnhe,arg); }
00102 inline real coth(const real & arg) throw() { return q_coth(*(double*)&arg); } // { return t_std_fct_call(t_cthe,arg); }
00103 
00104 inline real asinh(const real & arg) { return q_asnh(*(double*)&arg); } // { return t_std_fct_call(t_ashe,arg); }
00105 inline real acosh(const real & arg) { return q_acsh(*(double*)&arg); } // { return t_std_fct_call(t_ache,arg); }
00106 inline real atanh(const real & arg) { return q_atnh(*(double*)&arg); } // { return t_std_fct_call(t_anhe,arg); }
00107 inline real acoth(const real & arg) { return q_acth(*(double*)&arg); } // { return t_std_fct_call(t_athe,arg); }
00108 
00120 inline real erf(const real & arg)   { return q_erf(*(double*)&arg);  } // { return t_std_fct_call(t_athe,arg); }
00127 inline real erfc(const real & arg)  { return q_erfc(*(double*)&arg); } // { return t_std_fct_call(t_athe,arg); }
00128 
00129 //inline real pow(const real & arg,const real &expo) { return t_std_fct_call(t_powe,arg,expo); }
00130 inline real pow(const real & arg,const real &expo) { 
00131    real erg(arg),expohelp(expo); // expo semioptimal.. :I
00132    int rnd=t_grnd();
00133    t_srnd(NEAR);
00134    ExtReal a,b,r;
00135    t_ltoe((LongReal*)&erg,&a);
00136    t_ltoe((LongReal*)&expohelp,&b);
00137    t_powe(&a,&b,&r);
00138    t_etol(&r,(LongReal*)&erg);
00139    t_srnd(rnd);
00140    return erg;
00141 }
00142 
00143 inline real power(const real & arg,const int n)    { return pow(arg,n); }
00144 
00145 } // namespace cxsc
00146