static ex asinh_evalf(const ex & x) { if (is_exactly_a<numeric>(x)) return asinh(ex_to<numeric>(x)); return asinh(x).hold(); }
double z_time_from_redshiftinterval_flatuniverse(double h, double omega_m, double omega_l, double zmin, double zmax) { double prefactor = 2./(3*h*100.*km_cm/Mpc_cm*sqrt(omega_l)); double tmp = sqrt(omega_l/omega_m); return prefactor*(asinh(tmp*pow(1.+zmin, -1.5)) - asinh(tmp*pow(1.+zmax, -1.5))); }
void test_asinh() { static_assert((std::is_same<decltype(asinh((double)0)), double>::value), ""); static_assert((std::is_same<decltype(asinhf(0)), float>::value), ""); static_assert((std::is_same<decltype(asinhl(0)), long double>::value), ""); assert(asinh(0) == 0); }
void test_hyps() { double x; double y; RPN::Context cxt; cxt.insert("x", new RPN::VariableNode(&x)); cxt.insert("y", new RPN::VariableNode(&y)); RPN::Expression xsin("sinh x", cxt); RPN::Expression xcos("cosh x", cxt); RPN::Expression xtan("tanh x", cxt); RPN::Expression xsec("sech x", cxt); RPN::Expression xcsc("csch x", cxt); RPN::Expression xcot("coth x", cxt); RPN::Expression xasin("asinh x", cxt); RPN::Expression xacos("acosh x", cxt); RPN::Expression xatan("atanh x", cxt); RPN::Expression xasec("asech x", cxt); RPN::Expression xacsc("acsch x", cxt); RPN::Expression xacot("acoth x", cxt); // RPN::Expression xatan2("atanh2(x, y)", cxt); // RPN::Expression xacot2("acoth2(x, y)", cxt); for(x = -RPN::Constants::PI; x < RPN::Constants::PI; x += 0.097) { insist_equal(xsin.evaluate(), sinh(x)); insist_equal(xcos.evaluate(), cosh(x)); insist_equal(xtan.evaluate(), tanh(x)); insist_equal(xsec.evaluate(), 1.0/cosh(x)); insist_equal(xcsc.evaluate(), 1.0/sinh(x)); insist_equal(xcot.evaluate(), 1.0/tanh(x)); } for(x = -1; x < 1; x += 0.043) { insist_equal(xasin.evaluate(), asinh(x)); insist_equal(xacos.evaluate(), acosh(x)); insist_equal(xatan.evaluate(), atanh(x)); insist_equal(xasec.evaluate(), acosh(1.0/x)); insist_equal(xacsc.evaluate(), asinh(1.0/x)); insist_equal(xacot.evaluate(), atanh(1.0/x)); } /* for(x = -1; x < 1; x+= 0.069) { for(y = -1; y < 1; y += 0.73) { insist_equal(xatan2.evaluate(), atan2(x, y)); insist_equal(xacot2.evaluate(), atan2(y, x)); } }*/ }
TEST(AgradRev,asinh) { AVAR a = 0.2; AVAR f = asinh(a); EXPECT_FLOAT_EQ(asinh(0.2), f.val()); AVEC x = createAVEC(a); VEC grad_f; f.grad(x,grad_f); EXPECT_FLOAT_EQ(1.0/sqrt(0.2 * 0.2 + 1.0), grad_f[0]); }
Concentrating1dMesher::Concentrating1dMesher( Real start, Real end, Size size, const std::pair<Real, Real>& cPoints, const bool requireCPoint) : Fdm1dMesher(size) { QL_REQUIRE(end > start, "end must be larger than start"); const Real cPoint = cPoints.first; const Real density = cPoints.second == Null<Real>() ? Null<Real>() : cPoints.second*(end-start); QL_REQUIRE( cPoint == Null<Real>() || (cPoint >= start && cPoint <= end), "cPoint must be between start and end"); QL_REQUIRE(density == Null<Real>() || density > 0.0, "density > 0 required" ); const Real dx = 1.0/(size-1); if(cPoint != Null<Real>()) { std::vector<Real> u, z; boost::shared_ptr<Interpolation> transform; const Real c1 = asinh((start-cPoint)/density); const Real c2 = asinh((end-cPoint)/density); if(requireCPoint) { const Real z0 = - c1 / (c2-c1); const Real u0 = static_cast<int>(z0*(size-1)+0.5) / ((Real)(size-1)); u.push_back(0.0); u.push_back(u0); u.push_back(1.0); z.push_back(0.0); z.push_back(z0); z.push_back(1.0); transform = boost::shared_ptr<Interpolation>( new LinearInterpolation(u.begin(), u.end(), z.begin())); } for (Size i=1; i < size-1; ++i) { const Real li = requireCPoint ? (*transform)(i*dx) : i*dx; locations_[i] = cPoint + density*std::sinh(c1*(1.0-li)+c2*li); } } else { for (Size i=1; i < size-1; ++i) { locations_[i] = start + i*dx*(end-start); } } locations_.front() = start; locations_.back() = end; for (Size i=0; i < size-1; ++i) { dplus_[i] = dminus_[i+1] = locations_[i+1] - locations_[i]; } dplus_.back() = dminus_.front() = Null<Real>(); }
static ex asinh_conjugate(const ex & x) { // conjugate(asinh(x))==asinh(conjugate(x)) unless on the branch cuts which // run along the imaginary axis outside the interval [-I, +I]. if (x.info(info_flags::real)) return asinh(x); if (is_exactly_a<numeric>(x)) { const numeric x_re = ex_to<numeric>(x.real_part()); const numeric x_im = ex_to<numeric>(x.imag_part()); if (!x_re.is_zero() || (x_im > *_num_1_p && x_im < *_num1_p)) return asinh(x.conjugate()); } return conjugate_function(asinh(x)).hold(); }
int main() { double x = 1.0; double y = 1.0; int i = 1; acosh(x); asinh(x); atanh(x); cbrt(x); expm1(x); erf(x); erfc(x); isnan(x); j0(x); j1(x); jn(i,x); ilogb(x); logb(x); log1p(x); rint(x); y0(x); y1(x); yn(i,x); # ifdef _THREAD_SAFE gamma_r(x,&i); lgamma_r(x,&i); # else gamma(x); lgamma(x); # endif hypot(x,y); nextafter(x,y); remainder(x,y); scalb(x,y); return 0; }
void Foam::equationReader::evalDimsAsinhDimCheck ( const equationReader * eqnReader, const label index, const label i, const label storageOffset, label& storeIndex, dimensionSet& xDims, dimensionSet sourceDims ) const { if ( !xDims.dimensionless() && dimensionSet::debug ) { WarningIn("equationReader::evalDimsAsinhDimCheck") << "Dimension error thrown for operation [" << equationOperation::opName ( operator[](index)[i].operation() ) << "] in equation " << operator[](index).name() << ", given by:" << token::NL << token::TAB << operator[](index).rawText(); } dimensionedScalar ds("temp", xDims, 0.0); xDims.reset(asinh(ds).dimensions()); operator[](index)[i].assignOpDimsFunction ( &Foam::equationReader::evalDimsAsinh ); }
void AnalogLowPass::design (int numPoles, double stopBandDb) { if (m_numPoles != numPoles || m_stopBandDb != stopBandDb) { m_numPoles = numPoles; m_stopBandDb = stopBandDb; reset (); const double eps = std::sqrt (1. / (std::exp (stopBandDb * 0.1 * doubleLn10) - 1)); const double v0 = asinh (1 / eps) / numPoles; const double sinh_v0 = -sinh (v0); const double cosh_v0 = cosh (v0); const double fn = doublePi / (2 * numPoles); int k = 1; for (int i = numPoles / 2; --i >= 0; k+=2) { const double a = sinh_v0 * cos ((k - numPoles) * fn); const double b = cosh_v0 * sin ((k - numPoles) * fn); const double d2 = a * a + b * b; const double im = 1 / cos (k * fn); addPoleZeroConjugatePairs (complex_t (a / d2, b / d2), complex_t (0, im)); } if (numPoles & 1) { add (1 / sinh_v0, infinity()); } } }
static TACommandVerdict asinh_cmd(TAThread thread,TAInputStream stream) { double x, res; // Prepare x = readDouble(&stream); errno = 0; START_TARGET_OPERATION(thread); // Execute res = asinh(x); END_TARGET_OPERATION(thread); // Response writeDouble(thread, res); writeInt(thread, errno); sendResponse(thread); return taDefaultVerdict; }
double hyperbolic_arc_sine(double x, enum angle_type out_type) { switch (out_type) { case RAD: return asinh(x); break; case DEG: return radians_to_degrees(asinh(x)); break; case GRAD: return radians_to_grade(asinh(x)); } }
double for_large_negative(double a, double x) { double d3, d6, v_ax, X, theta, d9, d12; const double MY_PI = acos(-1); // Abramowitz and Stegun page 690 19.10.13 d3 = (x*x*x/48.0+a*x/2.0)/a; d6 = 3.0*x*x/4.0 - 2.0*a; d9 = (-7*x*x*x*x*x*x*x*x*x/5760 - 7*a*x*x*x*x*x*x*x/320 - 49*a*a*x*x*x*x*x/320 + 31*a*a*a*x*x*x/12 - 19*a*a*a*a*x)/(a*a*a); d12 = 153*x*x*x*x/8 - 186*a*x*x + 80*a*a; // from A/S 19.10.1 X = sqrt(x*x+4.0*a); theta = fabs(x)*X/4.0 + a*asinh(fabs(x)/(2*sqrt(a))); // notice the fabs()'s I need this to get the correct // theta when x is negative (not completely clear from // A/S I think) // A/S 19.10.4 v_ax = -0.5*log(X) -d3/(X*X*X) + d6/(X*X*X*X*X*X) - d9/(X*X*X*X*X*X*X*X*X) + d12/(X*X*X*X*X*X*X*X*X*X*X*X); // from 19.10.3 return 0.25*log(2*MY_PI) - 0.5*log(th_Gamma(0.5+a)) + theta + v_ax; }
void solve_cubic(double a, double b, double c, double d, int &N, double &x0, double &x1, double &x2) { // 0 = ax^3 + b*x^2 + c*x + d // First check if the "cubic" is actually a second order or first order curve if (std::abs(a) < 10*DBL_EPSILON){ if (std::abs(b) < 10*DBL_EPSILON){ // Linear solution if a = 0 and b = 0 x0 = -d/c; N = 1; return; } else{ // Quadratic solution(s) if a = 0 and b != 0 x0 = (-c+sqrt(c*c-4*b*d))/(2*b); x1 = (-c-sqrt(c*c-4*b*d))/(2*b); N = 2; return; } } // Ok, it is really a cubic // Discriminant double DELTA = 18*a*b*c*d-4*b*b*b*d+b*b*c*c-4*a*c*c*c-27*a*a*d*d; // Coefficients for the depressed cubic t^3+p*t+q = 0 double p = (3*a*c-b*b)/(3*a*a); double q = (2*b*b*b-9*a*b*c+27*a*a*d)/(27*a*a*a); if (DELTA<0) { // One real root double t0; if (4*p*p*p+27*q*q>0 && p<0) { t0 = -2.0*std::abs(q)/q*sqrt(-p/3.0)*cosh(1.0/3.0*acosh(-3.0*std::abs(q)/(2.0*p)*sqrt(-3.0/p))); } else { t0 = -2.0*sqrt(p/3.0)*sinh(1.0/3.0*asinh(3.0*q/(2.0*p)*sqrt(3.0/p))); } N = 1; x0 = t0-b/(3*a); x1 = t0-b/(3*a); x2 = t0-b/(3*a); } else //(DELTA>0) { // Three real roots double t0 = 2.0*sqrt(-p/3.0)*cos(1.0/3.0*acos(3.0*q/(2.0*p)*sqrt(-3.0/p))-0*2.0*M_PI/3.0); double t1 = 2.0*sqrt(-p/3.0)*cos(1.0/3.0*acos(3.0*q/(2.0*p)*sqrt(-3.0/p))-1*2.0*M_PI/3.0); double t2 = 2.0*sqrt(-p/3.0)*cos(1.0/3.0*acos(3.0*q/(2.0*p)*sqrt(-3.0/p))-2*2.0*M_PI/3.0); N = 3; x0 = t0-b/(3*a); x1 = t1-b/(3*a); x2 = t2-b/(3*a); } }
void newtonnu ( double ecc, double nu, double& e0, double& m ) { double sv, sine, cose; // --------------------- implementation --------------------- e0= 999999.9; m = 999999.9; sv = 0.00000001; // --------------------------- circular ------------------------ if ( fabs( ecc ) < sv ) { m = nu; e0= nu; } else // ---------------------- elliptical ----------------------- if ( ecc < 1.0-sv ) { sine= ( sqrt( 1.0 -ecc*ecc ) * sin(nu) ) / ( 1.0 +ecc*cos(nu) ); cose= ( ecc + cos(nu) ) / ( 1.0 + ecc*cos(nu) ); e0 = atan2( sine,cose ); m = e0 - ecc*sin(e0); } else // -------------------- hyperbolic -------------------- if ( ecc > 1.0 + sv ) { if ((ecc > 1.0 ) && (fabs(nu)+0.00001 < M_PI-acos(1.0 /ecc))) { sine= ( sqrt( ecc*ecc-1.0 ) * sin(nu) ) / ( 1.0 + ecc*cos(nu) ); #ifdef _MSC_BUILD e0 = StelUtils::asinh( sine ); #else e0 = asinh( sine ); #endif m = ecc*sinh(e0) - e0; } } else // ----------------- parabolic --------------------- if ( fabs(nu) < 168.0*M_PI/180.0 ) { e0= tan( nu*0.5 ); m = e0 + (e0*e0*e0)/3.0; } if ( ecc < 1.0 ) { m = fmod( m,2.0 *M_PI ); if ( m < 0.0 ) m = m + 2.0 *M_PI; e0 = fmod( e0,2.0 *M_PI ); } } // end newtonnu
// Vector asinh inline GVector asinh(const GVector &v) { GVector result(v.m_num); for (int i = 0; i < v.m_num; ++i) result.m_data[i] = asinh(v.m_data[i]); return result; }
/* {{{ php_asinh */ static double php_asinh(double z) { #ifdef HAVE_ASINH return(asinh(z)); #else return(log(z + sqrt(1 + pow(z, 2))) / log(M_E)); #endif }
void MultipoleExpansion::fill_radial_grid(double aa0, double rrmin, double rrmax){ // if loggrid use logarithmic grid else sinh a0 = aa0; rmax = rrmax; rmin = rrmin; double dmin = asinh(rmin/a0); double ra = asinh(rmax/a0)-dmin; if(loggrid){ dmin = log(rmin/a0); ra = log(rmax/rmin); } for(int i=0;i<NR;i++){ delta_grid.push_back(i*ra/(double)(NR-1)+dmin); if(loggrid) radial_grid.push_back(a0*exp(delta_grid[i])); else radial_grid.push_back(a0*sinh(delta_grid[i])); } }
float asinhf(float x) { if (isnanf(x)) { return (x * x); /* + -> * for Cheetah */ } else { return ((float) asinh((double) x)); } }
/*--------------------------------------------------------------------------*/ types::Function::ReturnValue sci_asinh(types::typed_list &in, int _iRetCount, types::typed_list &out) { types::Double* pDblIn = NULL; types::Double* pDblOut = NULL; if (in.size() != 1) { Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "asinh", 1); return types::Function::Error; } if (_iRetCount > 1) { Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "asinh", 1); return types::Function::Error; } if (in[0]->isDouble()) { pDblIn = in[0]->getAs<types::Double>(); pDblOut = new types::Double(pDblIn->getDims(), pDblIn->getDimsArray(), pDblIn->isComplex()); double* pInR = pDblIn->get(); double* pOutR = pDblOut->get(); int size = pDblIn->getSize(); if (pDblIn->isComplex()) { double* pInI = pDblIn->getImg(); double* pOutI = pDblOut->getImg(); for (int i = 0; i < size; i++) { //zcoss(-pInI[i], pInR[i], &pOutR[i], &pOutI[i]); std::complex<double> c(pInR[i], pInI[i]); std::complex<double> d = std::asinh(c); pOutR[i] = d.real(); pOutI[i] = d.imag(); } } else { for (int i = 0; i < size; i++) { pOutR[i] = asinh(pInR[i]); } } out.push_back(pDblOut); } else { ast::ExecVisitor exec; std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_asinh"; return Overload::call(wstFuncName, in, _iRetCount, out, &exec); } return types::Function::OK; }
/*--------------------------------------------------------------------------*/ SCICOS_BLOCKS_IMPEXP void asinh_blk(scicos_block *block,int flag) { int j = 0; if(flag==1){ for (j=0;j<block->insz[0];j++) { block->outptr[0][j]=asinh(block->inptr[0][j]); } } }
void Math_asinh(void *fp) { F_Math_asinh *f; f = fp; *f->ret = asinh(f->x); }
int main() { puts(" x asinh(x) log( x + sqrt(x*x+1))\n" "-------------------------------------------------------"); for ( double x = -2.0; x < 2.1; x += 0.5) printf("%6.2f %15f %20f\n", x, asinh(x), log( x + sqrt(x*x+1))); return 0; }
void testValues() { f = 2; double result; result = asinh(2.0); //@ assert f == 2; //@ assert vacuous: \false; }
TEST(AgradRev,asinh_boundry) { double inf = std::numeric_limits<double>::infinity(); AVAR a = inf; AVAR f = asinh(a); EXPECT_FLOAT_EQ(inf, f.val()); AVEC x = createAVEC(a); VEC g; f.grad(x,g); EXPECT_FLOAT_EQ(0.0, g[0]); AVAR b = -inf; AVAR e = asinh(b); EXPECT_FLOAT_EQ(-inf,e.val()); AVEC y = createAVEC(b); VEC h; e.grad(y,h); EXPECT_FLOAT_EQ(0.0, h[0]); }
static ex asinh_eval(const ex & x) { if (x.info(info_flags::numeric)) { // asinh(0) -> 0 if (x.is_zero()) return _ex0; // asinh(float) -> float if (!x.info(info_flags::crational)) return asinh(ex_to<numeric>(x)); // asinh() is odd if (x.info(info_flags::negative)) return -asinh(-x); } return asinh(x).hold(); }
TEST(AgradRev,asinh_val) { AVAR a = 0.2; AVAR f = asinh(a); EXPECT_FLOAT_EQ(0.198690110349, f.val()); AVEC x = createAVEC(a); VEC g; f.grad(x,g); EXPECT_FLOAT_EQ(1.0/sqrt(0.2 * 0.2 + 1.0), g[0]); }
void newtonnu ( double ecc, double nu, double& e0, double& m ) { double small, sine, cose; // --------------------- implementation --------------------- e0= 999999.9; m = 999999.9; small = 0.00000001; // --------------------------- circular ------------------------ if ( fabs( ecc ) < small ) { m = nu; e0= nu; } else // ---------------------- elliptical ----------------------- if ( ecc < 1.0-small ) { sine= ( sqrt( 1.0 -ecc*ecc ) * sin(nu) ) / ( 1.0 +ecc*cos(nu) ); cose= ( ecc + cos(nu) ) / ( 1.0 + ecc*cos(nu) ); e0 = atan2( sine,cose ); m = e0 - ecc*sin(e0); } else // -------------------- hyperbolic -------------------- if ( ecc > 1.0 + small ) { if ((ecc > 1.0 ) && (fabs(nu)+0.00001 < pi-acos(1.0 /ecc))) { sine= ( sqrt( ecc*ecc-1.0 ) * sin(nu) ) / ( 1.0 + ecc*cos(nu) ); e0 = asinh( sine ); m = ecc*sinh(e0) - e0; } } else // ----------------- parabolic --------------------- if ( fabs(nu) < 168.0*pi/180.0 ) { e0= tan( nu*0.5 ); m = e0 + (e0*e0*e0)/3.0; } if ( ecc < 1.0 ) { m = fmod( m,2.0 *pi ); if ( m < 0.0 ) m = m + 2.0 *pi; e0 = fmod( e0,2.0 *pi ); } } // end newtonnu
void arcsinh_rule_atomic_xy(double *xy, double *w, double const *p0, double const *p1, double const *p2, const int nu, double const *xu, double const *wu, const int nv, double const *xv, double const *wv, double *work) { double *u = work; double p0p1[2],p0p2[2],p1p2[2],invp1p2,Ah[4],xp[2],h,u0[2]; p0p1[0] = p1[0] - p0[0]; // x1-x0 p0p1[1] = p1[1] - p0[1]; // y1-y0 p0p2[0] = p2[0] - p0[0]; // x2-x0 p0p2[1] = p2[1] - p0[1]; // y2-y0 p1p2[0] = p2[0] - p1[0]; // x2-x1 p1p2[1] = p2[1] - p1[1]; // y2-y1 invp1p2 = 1.0/sqrt(p1p2[0]*p1p2[0] + p1p2[1]*p1p2[1] ); // inverse p1p2 p1p2[0]*= invp1p2; p1p2[1]*= invp1p2; h = -p1p2[0]*p0[1] + invp1p2*(p0p2[0]*p1[1] - p0p1[0]*p2[1]); Ah[0] = p1p2[0]*h; Ah[1] = -p1p2[1]*h; Ah[2] = p1p2[1]*h; Ah[3] = p1p2[0]*h; xp[0] = p1p2[0]*p0p1[0] + p1p2[1]*p0p1[1]; // x1p xp[1] = p1p2[0]*p0p2[0] + p1p2[1]*p0p2[1]; // x2p u0[0] = asinh(xp[0]/h); // u1 u0[1] = asinh(xp[1]/h)-u0[0]; // u2-u1 for (int i = 0; i < nu; i++) u[i] = u0[0] + u0[1]*xu[i]; for (int j = 0; j < nv; j++) for (int i = 0; i < nu; i++) // h(u1-u2) is absorbed into weights. w[i+nu*j] = fabs(h*u0[1])*wu[i]*wv[j]; for (int j = 0; j < nv; j++) for (int i = 0; i < nu; i++) { xy[2*(i+nu*j) ] = p0[0] + xv[j]*( Ah[0]*sinh(u[i]) + Ah[1] ); xy[2*(i+nu*j)+1] = p0[1] + xv[j]*( Ah[2]*sinh(u[i]) + Ah[3] ); } }
/* * call-seq: * Math.asinh(x) -> float * * Computes the inverse hyperbolic sine of <i>x</i>. */ static mrb_value math_asinh(mrb_state *mrb, mrb_value obj) { mrb_float x; mrb_get_args(mrb, "f", &x); x = asinh(x); return mrb_float_value(mrb, x); }