1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
// SPDX-FileContributor: 2003-22 Bradley M. Bell
// ----------------------------------------------------------------------------
/*
{xrst_begin near_equal.cpp}
NearEqual Function: Example and Test
####################################
File Name
*********
This file is called ``near_equal.cpp`` instead of
``NearEqual.cpp``
to avoid a name conflict with ``../lib/NearEqual.cpp``
in the corresponding Microsoft project file.
{xrst_literal
// BEGIN C++
// END C++
}
{xrst_end near_equal.cpp}
*/
// BEGIN C++
# include <cppad/utility/near_equal.hpp>
# include <complex>
bool Near_Equal(void)
{ bool ok = true;
typedef std::complex<double> Complex;
using CppAD::NearEqual;
// double
double x = 1.00000;
double y = 1.00001;
double a = .00003;
double r = .00003;
double zero = 0.;
double inf = 1. / zero;
double nan = 0. / zero;
ok &= NearEqual(x, y, zero, a);
ok &= NearEqual(x, y, r, zero);
ok &= NearEqual(x, y, r, a);
ok &= ! NearEqual(x, y, r / 10., a / 10.);
ok &= ! NearEqual(inf, inf, r, a);
ok &= ! NearEqual(-inf, -inf, r, a);
ok &= ! NearEqual(nan, nan, r, a);
// complex
Complex X(x, x / 2.);
Complex Y(y, y / 2.);
Complex Inf(inf, zero);
Complex Nan(zero, nan);
ok &= NearEqual(X, Y, zero, a);
ok &= NearEqual(X, Y, r, zero);
ok &= NearEqual(X, Y, r, a);
ok &= ! NearEqual(X, Y, r / 10., a / 10.);
ok &= ! NearEqual(Inf, Inf, r, a);
ok &= ! NearEqual(-Inf, -inf, r, a);
ok &= ! NearEqual(Nan, Nan, r, a);
return ok;
}
// END C++
|