本文整理匯總了C++中std::atan方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::atan方法的具體用法?C++ std::atan怎麽用?C++ std::atan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類std
的用法示例。
在下文中一共展示了std::atan方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: translateMouseCoords
double DirectionCanvas::translateMouseCoords(double trans_x, double trans_y)
{
// We now have 4 squares. One four every corner.
// With a cross in the middle.
// For every square we calculate a different tangent
// therefore we have to add of substract a number of degrees
double result = 0;
if (trans_x >= 0 && trans_y >= 0) {
// Right down
double arc_tan = trans_y / trans_x;
result = 90 + (atan(arc_tan)) * (180/M_PI);
} else if (trans_x <= 0 && trans_y >= 0) {
// Left down
trans_x = trans_x * -1;
double arc_tan = trans_y / trans_x;
result = 270 - (atan(arc_tan)) * (180/M_PI);
} else if (trans_x >= 0 && trans_y <= 0) {
// Right up
trans_y = trans_y * -1;
double arc_tan = trans_y / trans_x;
result = 90 - (atan(arc_tan)) * (180/M_PI);
} else if (trans_x <= 0 && trans_y <= 0) {
// Left up
trans_x = trans_x * -1;
trans_y = trans_y * -1;
double arc_tan = trans_y / trans_x;
result = 270 + (atan(arc_tan)) * (180/M_PI);
}
return result;
}
示例2: TEST_F
TEST_F(AgradFwdAtan,FvarFvarDouble) {
using stan::agrad::fvar;
using std::atan;
fvar<fvar<double> > x;
x.val_.val_ = 1.5;
x.val_.d_ = 2.0;
fvar<fvar<double> > a = atan(x);
EXPECT_FLOAT_EQ(atan(1.5), a.val_.val_);
EXPECT_FLOAT_EQ(2.0 / (1.0 + 1.5 * 1.5), a.val_.d_);
EXPECT_FLOAT_EQ(0, a.d_.val_);
EXPECT_FLOAT_EQ(0, a.d_.d_);
fvar<fvar<double> > y;
y.val_.val_ = 1.5;
y.d_.val_ = 2.0;
a = atan(y);
EXPECT_FLOAT_EQ(atan(1.5), a.val_.val_);
EXPECT_FLOAT_EQ(0, a.val_.d_);
EXPECT_FLOAT_EQ(2.0 / (1.0 + 1.5 * 1.5), a.d_.val_);
EXPECT_FLOAT_EQ(0, a.d_.d_);
}
示例3: computePrandtlMeyerFunction
//! Compute Prandtl-Meyer function.
double computePrandtlMeyerFunction( double machNumber, double ratioOfSpecificHeats )
{
// Declare local variables.
// Declare Mach number squared.
double machNumberSquared_ = pow( machNumber, 2.0 );
// Return value of Prandtl-Meyer function.
return sqrt ( ( ratioOfSpecificHeats + 1.0 ) / ( ratioOfSpecificHeats - 1.0 ) )
* atan ( sqrt ( ( ratioOfSpecificHeats - 1.0 ) / ( ratioOfSpecificHeats + 1.0 )
* ( machNumberSquared_ - 1.0 ) ) )
- atan( sqrt ( machNumberSquared_ - 1.0 ) );
}
示例4: main
int main () {
typedef const double c_dbl;
typedef const double * c_p_dbl;
typedef const double * const c_p_c_dbl;
typedef double * p_dbl;
typedef double & r_dbl;
cout << fixed << setprecision(3);
double my_double = 123.456789; // Set 1
cout << "Set1: " << my_double; // 123.457
r_dbl r_my_dbl = my_double; // Set 2 (ref. to my_double)
r_my_dbl = 987.654321; // 987.654
cout << "\nSet2: " << my_double;
p_dbl p_my_dbl = &my_double; // Set 3 (pointer to my_double)
my_double = 1.012345; // 1.012
cout << "\nSet3: " << *p_my_dbl;
c_dbl pi = atan(1.0) * 4.0; // Set 4
//r_dbl r_pi = pi; // error because pi is const
//cout << r_pi;
c_p_dbl c_p_pi = π // Set 5 (ptr. to a const double)
c_p_pi = &my_double; // adds const modifier
cout << "\nSet5: " << *c_p_pi; // 1.012
c_p_c_dbl cpc_pi = π // Set 6 (const ptr to const double)
//cpc_pi = &my_double; // error, can't change what const ptr points to
cout << "\nSet6: "<< *cpc_pi << endl; // 3.142
}
示例5: atan
void app::benchmark::task_func()
{
using std::atan;
mcal::irq::disable_all();
port_type::set_pin_high();
y = atan(x);
port_type::set_pin_low();
mcal::irq::enable_all();
// atan(4/10) = approx. 0.3805063771123649
const bool value_is_ok = (y > (numeric_type(38) / 100))
&& (y < (numeric_type(39) / 100));
if(value_is_ok)
{
// The benchmark is OK.
// Perform one nop and leave.
mcal::cpu::nop();
}
else
{
// The benchmark result is not OK!
// Remain in a blocking loop and crash the system.
for(;;) { mcal::cpu::nop(); }
}
}
示例6: ccdf_log_function
typename stan::return_type<T_y, T_loc, T_scale>::type
ccdf_log_function(const T_y& y, const T_loc& mu, const T_scale& sigma,
const T3&, const T4&, const T5&) {
using std::atan;
using stan::math::pi;
using std::log;
return log(0.5 - atan((y - mu) / sigma) / pi());
}
示例7: Solution
Solution() {
phip = 0.0;
using std::atan;
using std::cos;
using std::sin;
phi[X] = atan(-( a[X]/x0[X] )/( omega[X]/omega_prime[X] - omega_prime[X]/omega[X] ));
phi[Y] = atan(-( a[Y]/x0[Y] )/( omega[Y]/omega_prime[Y] - omega_prime[Y]/omega[Y] ));
phi[Z] = atan(-( a[Z]/x0[Z] )/( omega[Z]/omega_prime[Z] - omega_prime[Z]/omega[Z] ));
A[X] = x0[X] / cos(phi[X]);
A[Y] = x0[Y] / cos(phi[Y]);
A[Z] = x0[Z] / cos(phi[Z]);
B[X] = (omega[X]/omega_prime[X]) * sin(phi[X]);
B[Y] = (omega[Y]/omega_prime[Y]) * sin(phi[Y]);
B[Z] = (omega[Z]/omega_prime[Z]) * sin(phi[Z]);
}
示例8: complex_number_examples
void complex_number_examples()
{
Complex z1{0, 1};
std::cout << std::setprecision(std::numeric_limits<typename Complex::value_type>::digits10);
std::cout << std::scientific << std::fixed;
std::cout << "Print a complex number: " << z1 << std::endl;
std::cout << "Square it : " << z1*z1 << std::endl;
std::cout << "Real part : " << z1.real() << " = " << real(z1) << std::endl;
std::cout << "Imaginary part : " << z1.imag() << " = " << imag(z1) << std::endl;
using std::abs;
std::cout << "Absolute value : " << abs(z1) << std::endl;
std::cout << "Argument : " << arg(z1) << std::endl;
std::cout << "Norm : " << norm(z1) << std::endl;
std::cout << "Complex conjugate : " << conj(z1) << std::endl;
std::cout << "Projection onto Riemann sphere: " << proj(z1) << std::endl;
typename Complex::value_type r = 1;
typename Complex::value_type theta = 0.8;
using std::polar;
std::cout << "Polar coordinates (phase = 0) : " << polar(r) << std::endl;
std::cout << "Polar coordinates (phase !=0) : " << polar(r, theta) << std::endl;
std::cout << "\nElementary special functions:\n";
using std::exp;
std::cout << "exp(z1) = " << exp(z1) << std::endl;
using std::log;
std::cout << "log(z1) = " << log(z1) << std::endl;
using std::log10;
std::cout << "log10(z1) = " << log10(z1) << std::endl;
using std::pow;
std::cout << "pow(z1, z1) = " << pow(z1, z1) << std::endl;
using std::sqrt;
std::cout << "Take its square root : " << sqrt(z1) << std::endl;
using std::sin;
std::cout << "sin(z1) = " << sin(z1) << std::endl;
using std::cos;
std::cout << "cos(z1) = " << cos(z1) << std::endl;
using std::tan;
std::cout << "tan(z1) = " << tan(z1) << std::endl;
using std::asin;
std::cout << "asin(z1) = " << asin(z1) << std::endl;
using std::acos;
std::cout << "acos(z1) = " << acos(z1) << std::endl;
using std::atan;
std::cout << "atan(z1) = " << atan(z1) << std::endl;
using std::sinh;
std::cout << "sinh(z1) = " << sinh(z1) << std::endl;
using std::cosh;
std::cout << "cosh(z1) = " << cosh(z1) << std::endl;
using std::tanh;
std::cout << "tanh(z1) = " << tanh(z1) << std::endl;
using std::asinh;
std::cout << "asinh(z1) = " << asinh(z1) << std::endl;
using std::acosh;
std::cout << "acosh(z1) = " << acosh(z1) << std::endl;
using std::atanh;
std::cout << "atanh(z1) = " << atanh(z1) << std::endl;
}
示例9: cdf_hcauchy
inline double cdf_hcauchy(double x, double sigma, bool& throw_warning) {
#ifdef IEEE_754
if (ISNAN(x) || ISNAN(sigma))
return x+sigma;
#endif
if (sigma <= 0.0) {
throw_warning = true;
return NAN;
}
if (x < 0.0)
return 0.0;
return 2.0/M_PI * atan(x/sigma);
}
示例10: computeShockDeflectionAngle
//! Compute shock deflection angle.
double computeShockDeflectionAngle( double shockAngle, double machNumber,
double ratioOfSpecificHeats )
{
// Declare local variables.
double tangentOfDeflectionAngle_;
// Calculate tangent of deflection angle.
tangentOfDeflectionAngle_ = 2.0 * ( pow( machNumber * sin( shockAngle ), 2.0 ) - 1.0 )
/ ( tan( shockAngle ) * ( pow( machNumber, 2.0 )
* ( ratioOfSpecificHeats
+ cos( 2.0 * shockAngle ) ) + 2.0 ) );
// Return deflection angle.
return atan( tangentOfDeflectionAngle_ );
}
示例11: vectester
int vectester (Vector zerovec)
{
using std::abs;
using std::acos;
using std::asin;
using std::atan;
using std::floor;
using std::pow;
using std::sin;
using std::sqrt;
using std::tan;
typedef typename Vector::value_type Scalar;
Vector random_vec = zerovec;
Vector error_vec = zerovec;
std::srand(12345); // Fixed seed for reproduceability of failures
// Avoid divide by zero errors or acos(x>1) NaNs later
for (unsigned int i=0; i != random_vec.size(); ++i)
random_vec.raw_at(i) = .25 + (static_cast<Scalar>(std::rand())/RAND_MAX/2);
int returnval = 0;
one_test(2*random_vec - random_vec - random_vec);
one_test(3*random_vec - random_vec*3);
one_test((random_vec + random_vec)/2 - random_vec);
one_test(sqrt(random_vec) * sqrt(random_vec) - random_vec);
one_test(random_vec*random_vec - pow(random_vec,2));
one_test(sqrt(random_vec) - pow(random_vec,Scalar(.5)));
one_test(random_vec - sin(asin(random_vec)));
one_test(random_vec - tan(atan(random_vec)));
one_test(floor(random_vec / 2));
one_test(abs(random_vec) - random_vec);
return returnval;
}
示例12: Datan
static inline real Datan(real x, real y) {
using std::atan;
real d = x - y, xy = x * y;
return d ? (2 * xy > -1 ? atan( d / (1 + xy) ) : atan(x) - atan(y)) / d :
1 / (1 + xy);
}
示例13: cauchy_cdf
typename return_type<T_y,T_loc,T_scale>::type
cauchy_cdf(const T_y& y, const T_loc& mu, const T_scale& sigma) {
// Size checks
if ( !( stan::length(y) && stan::length(mu) && stan::length(sigma) ) ) return 1.0;
static const char* function = "stan::prob::cauchy_cdf(%1%)";
using stan::math::check_positive;
using stan::math::check_finite;
using stan::math::check_not_nan;
using stan::math::check_consistent_sizes;
using boost::math::tools::promote_args;
using stan::math::value_of;
double P(1.0);
if(!check_not_nan(function, y, "Random variable", &P))
return P;
if(!check_finite(function, mu, "Location parameter", &P))
return P;
if(!check_finite(function, sigma, "Scale parameter", &P))
return P;
if(!check_positive(function, sigma, "Scale parameter", &P))
return P;
if (!(check_consistent_sizes(function, y, mu, sigma,
"Random variable", "Location parameter", "Scale Parameter",
&P)))
return P;
// Wrap arguments in vectors
VectorView<const T_y> y_vec(y);
VectorView<const T_loc> mu_vec(mu);
VectorView<const T_scale> sigma_vec(sigma);
size_t N = max_size(y, mu, sigma);
agrad::OperandsAndPartials<T_y, T_loc, T_scale> operands_and_partials(y, mu, sigma);
std::fill(operands_and_partials.all_partials,
operands_and_partials.all_partials + operands_and_partials.nvaris, 0.0);
// Explicit return for extreme values
// The gradients are technically ill-defined, but treated as zero
for (size_t i = 0; i < stan::length(y); i++) {
if (value_of(y_vec[i]) == -std::numeric_limits<double>::infinity())
return operands_and_partials.to_var(0.0);
}
// Compute CDF and its gradients
using std::atan;
using stan::math::pi;
// Compute vectorized CDF and gradient
for (size_t n = 0; n < N; n++) {
// Explicit results for extreme values
// The gradients are technically ill-defined, but treated as zero
if (value_of(y_vec[n]) == std::numeric_limits<double>::infinity()) {
continue;
}
// Pull out values
const double y_dbl = value_of(y_vec[n]);
const double mu_dbl = value_of(mu_vec[n]);
const double sigma_inv_dbl = 1.0 / value_of(sigma_vec[n]);
const double z = (y_dbl - mu_dbl) * sigma_inv_dbl;
// Compute
const double Pn = atan(z) / pi() + 0.5;
P *= Pn;
if (!is_constant_struct<T_y>::value)
operands_and_partials.d_x1[n]
+= sigma_inv_dbl / (pi() * (1.0 + z * z) * Pn);
if (!is_constant_struct<T_loc>::value)
operands_and_partials.d_x2[n]
+= - sigma_inv_dbl / (pi() * (1.0 + z * z) * Pn);
if (!is_constant_struct<T_scale>::value)
operands_and_partials.d_x3[n]
+= - z * sigma_inv_dbl / (pi() * (1.0 + z * z) * Pn);
}
if (!is_constant_struct<T_y>::value) {
for(size_t n = 0; n < stan::length(y); ++n) operands_and_partials.d_x1[n] *= P;
}
if (!is_constant_struct<T_loc>::value) {
for(size_t n = 0; n < stan::length(mu); ++n) operands_and_partials.d_x2[n] *= P;
}
if (!is_constant_struct<T_scale>::value) {
//.........這裏部分代碼省略.........
示例14: deriv_eq1
void deriv_eq1(T *ans, T &x, double *h, int &size){
for (int i=0; i<size; i++){
ans[i] = ( atan(x+h[i])-atan(x) )/h[i];
}
}
示例15: vectester
int vectester (Vector zerovec)
{
using std::abs;
using std::acos;
using std::asin;
using std::atan;
using std::ceil;
using std::cos;
using std::cosh;
using std::exp;
using std::fabs;
using std::floor;
using std::log;
using std::log10;
using std::pow;
using std::sin;
using std::sinh;
using std::sqrt;
using std::tan;
using std::tanh;
typedef typename ValueType<Vector>::type DualScalar;
typedef typename DualScalar::value_type Scalar;
Vector random_vec = zerovec;
typename DerivativeType<Vector>::type error_vec = 0;
std::srand(12345); // Fixed seed for reproduceability of failures
// Avoid divide by zero errors later
for (unsigned int i=0; i != N; ++i)
{
random_vec.raw_at(i) = .25 + (static_cast<Scalar>(std::rand())/RAND_MAX);
random_vec.raw_at(i).derivatives() = 1;
}
// Scalar pi = acos(Scalar(-1));
int returnval = 0;
// Running non-derivatives tests with DualNumbers sometimes catches
// problems too
one_test(2*random_vec - random_vec - random_vec);
one_test(3*random_vec - random_vec*3);
one_test((random_vec + random_vec)/2 - random_vec);
// We had a problem in user code with the mixing of long double and
// DualNumber<double, DynamicSparseNumberArray>
one_test(2.L*random_vec - random_vec - 1.f*random_vec);
// pow() is still having problems with sparse vectors? Disabling it
// for now.
one_test(sqrt(random_vec) * sqrt(random_vec) - random_vec);
// one_test(random_vec*random_vec - pow(random_vec,2));
// one_test(sqrt(random_vec) - pow(random_vec,Scalar(.5)));
// functions which map zero to non-zero are not defined for sparse
// vectors. This includes exp(), log(), cos(), cosh(),
// pow(scalar,sparse), scalar/sparse, sparse +/- scalar...
// one_test(log(exp(random_vec)) - random_vec);
// one_test(exp(log(random_vec)) - random_vec);
// one_test(exp(random_vec) - pow(exp(Scalar(1)), random_vec));
// one_test(tan(random_vec) - sin(random_vec)/cos(random_vec));
one_test(random_vec - sin(asin(random_vec)));
// one_test(random_vec - cos(acos(random_vec)));
one_test(random_vec - tan(atan(random_vec)));
// one_test(1 - pow(sin(random_vec), 2) - pow(cos(random_vec), 2));
// one_test(cos(random_vec) - sin(random_vec + pi/2));
// one_test(tanh(random_vec) - sinh(random_vec)/cosh(random_vec));
// one_test(1 + pow(sinh(random_vec), 2) - pow(cosh(random_vec), 2));
// one_test(log10(random_vec) - log(random_vec)/log(Scalar(10)));
one_test(floor(random_vec / 2));
// one_test(ceil(random_vec / 2 - 1));
one_test(abs(random_vec) - random_vec);
// one_test(fabs(random_vec-.75) - abs(random_vec-.75));
// And now for derivatives tests
// one_test(derivatives(pow(sin(random_vec-2),2)) -
// 2*sin(random_vec)*cos(random_vec));
// one_test(derivatives(cos(2*random_vec)) + 2*sin(2*random_vec));
// one_test(derivatives(tan(.5*random_vec)) - .5/pow(cos(.5*random_vec),2));
// one_test(derivatives(sqrt(random_vec+1)) - 1/sqrt(random_vec+1)/2);
// one_test(derivatives((random_vec-1)*(random_vec-1)) - 2*(random_vec-1));
//.........這裏部分代碼省略.........