// Ceres Solver - A fast non-linear least squares minimizer
// Copyright 2024 Google Inc. All rights reserved.
// http://ceres-solver.org/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
// * Neither the name of Google Inc. nor the names of its contributors may be
//   used to endorse or promote products derived from this software without
//   specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Author: keir@google.com (Keir Mierle)

#include "ceres/jet.h"

#include <Eigen/Dense>
#include <algorithm>
#include <cfenv>
#include <cmath>

#include "absl/log/log.h"
#include "ceres/test_util.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

// The floating-point environment access and modification is only meaningful
// with the following pragma.
#ifdef _MSC_VER
#pragma float_control(precise, on, push)
#pragma fenv_access(on)
#elif !(defined(__ARM_ARCH) && __ARM_ARCH >= 8) && !defined(__MINGW32__)
// NOTE: FENV_ACCESS cannot be set to ON when targeting arm(v8) and MinGW
#pragma STDC FENV_ACCESS ON
#else
#define CERES_NO_FENV_ACCESS
#endif

namespace ceres::internal {

namespace {

constexpr double kE = 2.71828182845904523536;

using J = Jet<double, 2>;
// Don't care about the dual part for scalar part categorization and comparison
// tests
template <typename T>
using J0 = Jet<T, 0>;
using J0d = J0<double>;

// Convenient shorthand for making a jet.
J MakeJet(double a, double v0, double v1) {
  J z;
  z.a = a;
  z.v[0] = v0;
  z.v[1] = v1;
  return z;
}

constexpr double kTolerance = 1e-13;

// Stores the floating-point environment containing active floating-point
// exceptions, rounding mode, etc., and restores it upon destruction.
//
// Useful for avoiding side-effects.
class Fenv {
 public:
  Fenv() { std::fegetenv(&e); }
  ~Fenv() { std::fesetenv(&e); }

  Fenv(const Fenv&) = delete;
  Fenv& operator=(const Fenv&) = delete;

 private:
  std::fenv_t e;
};

bool AreAlmostEqual(double x, double y, double max_abs_relative_difference) {
  if (std::isnan(x) && std::isnan(y)) {
    return true;
  }

  if (std::isinf(x) && std::isinf(y)) {
    return (std::signbit(x) == std::signbit(y));
  }

  Fenv env;  // Do not leak floating-point exceptions to the caller
  double absolute_difference = std::abs(x - y);
  double relative_difference =
      absolute_difference / std::max(std::abs(x), std::abs(y));

  if (std::fpclassify(x) == FP_ZERO || std::fpclassify(y) == FP_ZERO) {
    // If x or y is exactly zero, then relative difference doesn't have any
    // meaning. Take the absolute difference instead.
    relative_difference = absolute_difference;
  }
  return std::islessequal(relative_difference, max_abs_relative_difference);
}

MATCHER_P2(IsAlmostEqualToWithTolerance,
           y,
           tolerance,
           "is almost equal to " + testing::PrintToString(y) +
               " with tolerance " + testing::PrintToString(tolerance)) {
  const bool result = (AreAlmostEqual(arg.a, y.a, tolerance) &&
                       AreAlmostEqual(arg.v[0], y.v[0], tolerance) &&
                       AreAlmostEqual(arg.v[1], y.v[1], tolerance));
  if (!result) {
    *result_listener << "\nexpected - actual : " << y - arg;
  }
  return result;
}

MATCHER_P(IsAlmostEqualTo, y, "") {
  return ExplainMatchResult(
      IsAlmostEqualToWithTolerance(y, kTolerance), arg, result_listener);
}

const double kStep = 1e-8;
const double kNumericalTolerance = 1e-6;  // Numeric derivation is quite inexact

// Differentiate using Jet and confirm results with numerical derivation.
template <typename Function>
void NumericalTest(const char* name, const Function& f, const double x) {
  const double exact_dx = f(MakeJet(x, 1.0, 0.0)).v[0];
  const double estimated_dx =
      (f(J(x + kStep)).a - f(J(x - kStep)).a) / (2.0 * kStep);
  VLOG(1) << name << "(" << x << "), exact dx: " << exact_dx
          << ", estimated dx: " << estimated_dx;
  ExpectClose(exact_dx, estimated_dx, kNumericalTolerance);
}

// Same as NumericalTest, but given a function taking two arguments.
template <typename Function>
void NumericalTest2(const char* name,
                    const Function& f,
                    const double x,
                    const double y) {
  const J exact_delta = f(MakeJet(x, 1.0, 0.0), MakeJet(y, 0.0, 1.0));
  const double exact_dx = exact_delta.v[0];
  const double exact_dy = exact_delta.v[1];

  // Sanity check - these should be equivalent:
  EXPECT_EQ(exact_dx, f(MakeJet(x, 1.0, 0.0), MakeJet(y, 0.0, 0.0)).v[0]);
  EXPECT_EQ(exact_dx, f(MakeJet(x, 0.0, 1.0), MakeJet(y, 0.0, 0.0)).v[1]);
  EXPECT_EQ(exact_dy, f(MakeJet(x, 0.0, 0.0), MakeJet(y, 1.0, 0.0)).v[0]);
  EXPECT_EQ(exact_dy, f(MakeJet(x, 0.0, 0.0), MakeJet(y, 0.0, 1.0)).v[1]);

  const double estimated_dx =
      (f(J(x + kStep), J(y)).a - f(J(x - kStep), J(y)).a) / (2.0 * kStep);
  const double estimated_dy =
      (f(J(x), J(y + kStep)).a - f(J(x), J(y - kStep)).a) / (2.0 * kStep);
  VLOG(1) << name << "(" << x << ", " << y << "), exact dx: " << exact_dx
          << ", estimated dx: " << estimated_dx;
  ExpectClose(exact_dx, estimated_dx, kNumericalTolerance);
  VLOG(1) << name << "(" << x << ", " << y << "), exact dy: " << exact_dy
          << ", estimated dy: " << estimated_dy;
  ExpectClose(exact_dy, estimated_dy, kNumericalTolerance);
}

}  // namespace

// Pick arbitrary values for x and y.
const J x = MakeJet(2.3, -2.7, 1e-3);
const J y = MakeJet(1.7, 0.5, 1e+2);
const J z = MakeJet(1e-6, 1e-4, 1e-2);

TEST(Jet, Elementary) {
  EXPECT_THAT((x * y) / x, IsAlmostEqualTo(y));
  EXPECT_THAT(sqrt(x * x), IsAlmostEqualTo(x));
  EXPECT_THAT(sqrt(y) * sqrt(y), IsAlmostEqualTo(y));

  NumericalTest("sqrt", sqrt<double, 2>, 0.00001);
  NumericalTest("sqrt", sqrt<double, 2>, 1.0);

  EXPECT_THAT(x + 1.0, IsAlmostEqualTo(1.0 + x));
  {
    J c = x;
    c += 1.0;
    EXPECT_THAT(c, IsAlmostEqualTo(1.0 + x));
  }

  EXPECT_THAT(-(x - 1.0), IsAlmostEqualTo(1.0 - x));
  {
    J c = x;
    c -= 1.0;
    EXPECT_THAT(c, IsAlmostEqualTo(x - 1.0));
  }

  EXPECT_THAT((x * 5.0) / 5.0, IsAlmostEqualTo((x / 5.0) * 5.0));
  EXPECT_THAT((x * 5.0) / 5.0, IsAlmostEqualTo(x));
  EXPECT_THAT((x / 5.0) * 5.0, IsAlmostEqualTo(x));

  {
    J c = x;
    c /= 5.0;
    J d = x;
    d *= 5.0;
    EXPECT_THAT(c, IsAlmostEqualTo(x / 5.0));
    EXPECT_THAT(d, IsAlmostEqualTo(5.0 * x));
  }

  EXPECT_THAT(1.0 / (y / x), IsAlmostEqualTo(x / y));
}

TEST(Jet, Trigonometric) {
  EXPECT_THAT(cos(2.0 * x), IsAlmostEqualTo(cos(x) * cos(x) - sin(x) * sin(x)));
  EXPECT_THAT(sin(2.0 * x), IsAlmostEqualTo(2.0 * sin(x) * cos(x)));
  EXPECT_THAT(sin(x) * sin(x) + cos(x) * cos(x), IsAlmostEqualTo(J(1.0)));

  {
    J t = MakeJet(0.7, -0.3, +1.5);
    J r = MakeJet(2.3, 0.13, -2.4);
    EXPECT_THAT(atan2(r * sin(t), r * cos(t)), IsAlmostEqualTo(t));
  }

  EXPECT_THAT(sin(x) / cos(x), IsAlmostEqualTo(tan(x)));
  EXPECT_THAT(tan(atan(x)), IsAlmostEqualTo(x));

  {
    J a = MakeJet(0.1, -2.7, 1e-3);
    EXPECT_THAT(cos(acos(a)), IsAlmostEqualTo(a));
    EXPECT_THAT(acos(cos(a)), IsAlmostEqualTo(a));

    J b = MakeJet(0.6, 0.5, 1e+2);
    EXPECT_THAT(cos(acos(b)), IsAlmostEqualTo(b));
    EXPECT_THAT(acos(cos(b)), IsAlmostEqualTo(b));
  }

  {
    J a = MakeJet(0.1, -2.7, 1e-3);
    EXPECT_THAT(sin(asin(a)), IsAlmostEqualTo(a));
    EXPECT_THAT(asin(sin(a)), IsAlmostEqualTo(a));

    J b = MakeJet(0.4, 0.5, 1e+2);
    EXPECT_THAT(sin(asin(b)), IsAlmostEqualTo(b));
    EXPECT_THAT(asin(sin(b)), IsAlmostEqualTo(b));
  }
}

TEST(Jet, Hyperbolic) {
  // cosh(x)*cosh(x) - sinh(x)*sinh(x) = 1
  EXPECT_THAT(cosh(x) * cosh(x) - sinh(x) * sinh(x), IsAlmostEqualTo(J(1.0)));

  // tanh(x + y) = (tanh(x) + tanh(y)) / (1 + tanh(x) tanh(y))
  EXPECT_THAT(
      tanh(x + y),
      IsAlmostEqualTo((tanh(x) + tanh(y)) / (J(1.0) + tanh(x) * tanh(y))));
}

TEST(Jet, Abs) {
  EXPECT_THAT(abs(-x * x), IsAlmostEqualTo(x * x));
  EXPECT_THAT(abs(-x), IsAlmostEqualTo(sqrt(x * x)));

  {
    J a = MakeJet(-std::numeric_limits<double>::quiet_NaN(), 2.0, 4.0);
    J b = abs(a);
    EXPECT_TRUE(std::signbit(b.v[0]));
    EXPECT_TRUE(std::signbit(b.v[1]));
  }
}

#if defined(CERES_HAS_POSIX_BESSEL_FUNCTIONS) || \
    defined(CERES_HAS_CPP17_BESSEL_FUNCTIONS)
TEST(Jet, Bessel) {
  J zero = J(0.0);
  J z = MakeJet(0.1, -2.7, 1e-3);

#ifdef CERES_HAS_POSIX_BESSEL_FUNCTIONS
  EXPECT_THAT(BesselJ0(zero), IsAlmostEqualTo(J(1.0)));
  EXPECT_THAT(BesselJ1(zero), IsAlmostEqualTo(zero));
  EXPECT_THAT(BesselJn(2, zero), IsAlmostEqualTo(zero));
  EXPECT_THAT(BesselJn(3, zero), IsAlmostEqualTo(zero));

  EXPECT_THAT(BesselJ0(z), IsAlmostEqualTo(BesselJn(0, z)));
  EXPECT_THAT(BesselJ1(z), IsAlmostEqualTo(BesselJn(1, z)));

  // See formula http://dlmf.nist.gov/10.6.E1
  EXPECT_THAT(BesselJ0(z) + BesselJn(2, z),
              IsAlmostEqualTo((2.0 / z) * BesselJ1(z)));
#endif  // CERES_HAS_POSIX_BESSEL_FUNCTIONS

#ifdef CERES_HAS_CPP17_BESSEL_FUNCTIONS
  EXPECT_THAT(cyl_bessel_j(0, zero), IsAlmostEqualTo(J(1.0)));
  EXPECT_THAT(cyl_bessel_j(1, zero), IsAlmostEqualTo(zero));
  EXPECT_THAT(cyl_bessel_j(2, zero), IsAlmostEqualTo(zero));
  EXPECT_THAT(cyl_bessel_j(3, zero), IsAlmostEqualTo(zero));

  EXPECT_THAT(cyl_bessel_j(0, z), IsAlmostEqualTo(BesselJn(0, z)));
  EXPECT_THAT(cyl_bessel_j(1, z), IsAlmostEqualTo(BesselJn(1, z)));

  // MSVC Bessel functions and their derivatives produce errors slightly above
  // kTolerance. Provide an alternative variant with a relaxed threshold.
  constexpr double kRelaxedTolerance = 10 * kTolerance;

  // See formula http://dlmf.nist.gov/10.6.E1
  EXPECT_THAT(cyl_bessel_j(0, z) + cyl_bessel_j(2, z),
              IsAlmostEqualToWithTolerance((2.0 / z) * cyl_bessel_j(1, z),
                                           kRelaxedTolerance));

  // MSVC does not throw an exception on invalid first argument
#ifndef _MSC_VER
  EXPECT_THROW(cyl_bessel_j(-1, zero), std::domain_error);
#endif  // defined(_MSC_VER)
#endif  // defined(CERES_HAS_CPP17_BESSEL_FUNCTIONS)
}
#endif  // defined(CERES_HAS_POSIX_BESSEL_FUNCTIONS) ||
        // defined(CERES_HAS_CPP17_BESSEL_FUNCTIONS)

TEST(Jet, Floor) {
  {  // floor of a positive number works.
    J a = MakeJet(0.1, -2.7, 1e-3);
    J b = floor(a);
    J expected = MakeJet(floor(a.a), 0.0, 0.0);
    EXPECT_EQ(expected, b);
  }

  {  // floor of a negative number works.
    J a = MakeJet(-1.1, -2.7, 1e-3);
    J b = floor(a);
    J expected = MakeJet(floor(a.a), 0.0, 0.0);
    EXPECT_EQ(expected, b);
  }

  {  // floor of a positive number works.
    J a = MakeJet(10.123, -2.7, 1e-3);
    J b = floor(a);
    J expected = MakeJet(floor(a.a), 0.0, 0.0);
    EXPECT_EQ(expected, b);
  }
}

TEST(Jet, Ceil) {
  {  // ceil of a positive number works.
    J a = MakeJet(0.1, -2.7, 1e-3);
    J b = ceil(a);
    J expected = MakeJet(ceil(a.a), 0.0, 0.0);
    EXPECT_EQ(expected, b);
  }

  {  // ceil of a negative number works.
    J a = MakeJet(-1.1, -2.7, 1e-3);
    J b = ceil(a);
    J expected = MakeJet(ceil(a.a), 0.0, 0.0);
    EXPECT_EQ(expected, b);
  }

  {  // ceil of a positive number works.
    J a = MakeJet(10.123, -2.7, 1e-3);
    J b = ceil(a);
    J expected = MakeJet(ceil(a.a), 0.0, 0.0);
    EXPECT_EQ(expected, b);
  }
}

TEST(Jet, Erf) {
  {  // erf works.
    J a = MakeJet(10.123, -2.7, 1e-3);
    J b = erf(a);
    J expected = MakeJet(erf(a.a), 0.0, 0.0);
    EXPECT_EQ(expected, b);
  }
  NumericalTest("erf", erf<double, 2>, -1.0);
  NumericalTest("erf", erf<double, 2>, 1e-5);
  NumericalTest("erf", erf<double, 2>, 0.5);
  NumericalTest("erf", erf<double, 2>, 100.0);
}

TEST(Jet, Erfc) {
  {  // erfc works.
    J a = MakeJet(10.123, -2.7, 1e-3);
    J b = erfc(a);
    J expected = MakeJet(erfc(a.a), 0.0, 0.0);
    EXPECT_EQ(expected, b);
  }
  NumericalTest("erfc", erfc<double, 2>, -1.0);
  NumericalTest("erfc", erfc<double, 2>, 1e-5);
  NumericalTest("erfc", erfc<double, 2>, 0.5);
  NumericalTest("erfc", erfc<double, 2>, 100.0);
}

TEST(Jet, Cbrt) {
  EXPECT_THAT(cbrt(x * x * x), IsAlmostEqualTo(x));
  EXPECT_THAT(cbrt(y) * cbrt(y) * cbrt(y), IsAlmostEqualTo(y));
  EXPECT_THAT(cbrt(x), IsAlmostEqualTo(pow(x, 1.0 / 3.0)));

  NumericalTest("cbrt", cbrt<double, 2>, -1.0);
  NumericalTest("cbrt", cbrt<double, 2>, -1e-5);
  NumericalTest("cbrt", cbrt<double, 2>, 1e-5);
  NumericalTest("cbrt", cbrt<double, 2>, 1.0);
}

TEST(Jet, Log1p) {
  EXPECT_THAT(log1p(expm1(x)), IsAlmostEqualTo(x));
  EXPECT_THAT(log1p(x), IsAlmostEqualTo(log(J{1} + x)));

  {  // log1p(x) does not loose precision for small x
    J x = MakeJet(1e-16, 1e-8, 1e-4);
    EXPECT_THAT(log1p(x),
                IsAlmostEqualTo(MakeJet(9.9999999999999998e-17, 1e-8, 1e-4)));
    // log(1 + x) collapses to 0
    J v = log(J{1} + x);
    EXPECT_TRUE(v.a == 0);
  }
}

TEST(Jet, Expm1) {
  EXPECT_THAT(expm1(log1p(x)), IsAlmostEqualTo(x));
  EXPECT_THAT(expm1(x), IsAlmostEqualTo(exp(x) - 1.0));

  {  // expm1(x) does not loose precision for small x
    J x = MakeJet(9.9999999999999998e-17, 1e-8, 1e-4);
    EXPECT_THAT(expm1(x), IsAlmostEqualTo(MakeJet(1e-16, 1e-8, 1e-4)));
    // exp(x) - 1 collapses to 0
    J v = exp(x) - J{1};
    EXPECT_TRUE(v.a == 0);
  }
}

TEST(Jet, Exp2) {
  EXPECT_THAT(exp2(x), IsAlmostEqualTo(exp(x * log(2.0))));
  NumericalTest("exp2", exp2<double, 2>, -1.0);
  NumericalTest("exp2", exp2<double, 2>, -1e-5);
  NumericalTest("exp2", exp2<double, 2>, -1e-200);
  NumericalTest("exp2", exp2<double, 2>, 0.0);
  NumericalTest("exp2", exp2<double, 2>, 1e-200);
  NumericalTest("exp2", exp2<double, 2>, 1e-5);
  NumericalTest("exp2", exp2<double, 2>, 1.0);
}

TEST(Jet, Log) { EXPECT_THAT(log(exp(x)), IsAlmostEqualTo(x)); }

TEST(Jet, Log10) {
  EXPECT_THAT(log10(x), IsAlmostEqualTo(log(x) / log(10)));
  NumericalTest("log10", log10<double, 2>, 1e-5);
  NumericalTest("log10", log10<double, 2>, 1.0);
  NumericalTest("log10", log10<double, 2>, 98.76);
}

TEST(Jet, Log2) {
  EXPECT_THAT(log2(x), IsAlmostEqualTo(log(x) / log(2)));
  NumericalTest("log2", log2<double, 2>, 1e-5);
  NumericalTest("log2", log2<double, 2>, 1.0);
  NumericalTest("log2", log2<double, 2>, 100.0);
}

TEST(Jet, Norm) {
  EXPECT_THAT(norm(x), IsAlmostEqualTo(x * x));
  EXPECT_THAT(norm(-x), IsAlmostEqualTo(x * x));
}

TEST(Jet, Pow) {
  EXPECT_THAT(pow(x, 1.0), IsAlmostEqualTo(x));
  EXPECT_THAT(pow(x, MakeJet(1.0, 0.0, 0.0)), IsAlmostEqualTo(x));
  EXPECT_THAT(pow(kE, log(x)), IsAlmostEqualTo(x));
  EXPECT_THAT(pow(MakeJet(kE, 0., 0.), log(x)), IsAlmostEqualTo(x));
  EXPECT_THAT(pow(x, y),
              IsAlmostEqualTo(pow(MakeJet(kE, 0.0, 0.0), y * log(x))));

  // Specially cases

  // pow(0, y) == 0 for y > 1, with both arguments Jets.
  EXPECT_THAT(pow(MakeJet(0, 1, 2), MakeJet(2, 3, 4)),
              IsAlmostEqualTo(MakeJet(0, 0, 0)));

  // pow(0, y) == 0 for y == 1, with both arguments Jets.
  EXPECT_THAT(pow(MakeJet(0, 1, 2), MakeJet(1, 3, 4)),
              IsAlmostEqualTo(MakeJet(0, 1, 2)));

  // pow(0, <1) is not finite, with both arguments Jets.
  {
    for (int i = 1; i < 10; i++) {
      J a = MakeJet(0, 1, 2);
      J b = MakeJet(i * 0.1, 3, 4);  // b = 0.1 ... 0.9
      J c = pow(a, b);
      EXPECT_EQ(c.a, 0.0) << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_FALSE(isfinite(c.v[0]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_FALSE(isfinite(c.v[1]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
    }

    for (int i = -10; i < 0; i++) {
      J a = MakeJet(0, 1, 2);
      J b = MakeJet(i * 0.1, 3, 4);  // b = -1,-0.9 ... -0.1
      J c = pow(a, b);
      EXPECT_FALSE(isfinite(c.a))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_FALSE(isfinite(c.v[0]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_FALSE(isfinite(c.v[1]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
    }

    // The special case of 0^0 = 1 defined by the C standard.
    {
      J a = MakeJet(0, 1, 2);
      J b = MakeJet(0, 3, 4);
      J c = pow(a, b);
      EXPECT_EQ(c.a, 1.0) << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_FALSE(isfinite(c.v[0]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_FALSE(isfinite(c.v[1]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
    }
  }

  // pow(<0, b) is correct for integer b.
  {
    J a = MakeJet(-1.5, 3, 4);

    // b integer:
    for (int i = -10; i <= 10; i++) {
      J b = MakeJet(i, 0, 5);
      J c = pow(a, b);

      EXPECT_TRUE(AreAlmostEqual(c.a, pow(-1.5, i), kTolerance))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_TRUE(isfinite(c.v[0]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_FALSE(isfinite(c.v[1]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_TRUE(
          AreAlmostEqual(c.v[0], i * pow(-1.5, i - 1) * 3.0, kTolerance))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
    }
  }

  // pow(<0, b) is correct for noninteger b.
  {
    J a = MakeJet(-1.5, 3, 4);
    J b = MakeJet(-2.5, 0, 5);
    J c = pow(a, b);
    EXPECT_FALSE(isfinite(c.a))
        << "\na: " << a << "\nb: " << b << "\na^b: " << c;
    EXPECT_FALSE(isfinite(c.v[0]))
        << "\na: " << a << "\nb: " << b << "\na^b: " << c;
    EXPECT_FALSE(isfinite(c.v[1]))
        << "\na: " << a << "\nb: " << b << "\na^b: " << c;
  }

  // pow(0,y) == 0 for y == 2, with the second argument a Jet.
  EXPECT_THAT(pow(0.0, MakeJet(2, 3, 4)), IsAlmostEqualTo(MakeJet(0, 0, 0)));

  // pow(<0,y) is correct for integer y.
  {
    double a = -1.5;
    for (int i = -10; i <= 10; i++) {
      J b = MakeJet(i, 3, 0);
      J c = pow(a, b);
      ExpectClose(c.a, pow(-1.5, i), kTolerance);
      EXPECT_FALSE(isfinite(c.v[0]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      EXPECT_TRUE(isfinite(c.v[1]))
          << "\na: " << a << "\nb: " << b << "\na^b: " << c;
      ExpectClose(c.v[1], 0, kTolerance);
    }
  }

  // pow(<0,y) is correct for noninteger y.
  {
    double a = -1.5;
    J b = MakeJet(-3.14, 3, 0);
    J c = pow(a, b);
    EXPECT_FALSE(isfinite(c.a))
        << "\na: " << a << "\nb: " << b << "\na^b: " << c;
    EXPECT_FALSE(isfinite(c.v[0]))
        << "\na: " << a << "\nb: " << b << "\na^b: " << c;
    EXPECT_FALSE(isfinite(c.v[1]))
        << "\na: " << a << "\nb: " << b << "\na^b: " << c;
  }
}

TEST(Jet, Hypot2) {
  // Resolve the ambiguity between two and three argument hypot overloads
  using Hypot2 = J(const J&, const J&);
  auto* const hypot2 = static_cast<Hypot2*>(&hypot<double, 2>);

  // clang-format off
  NumericalTest2("hypot2", hypot2,  0.0,   1e-5);
  NumericalTest2("hypot2", hypot2, -1e-5,  0.0);
  NumericalTest2("hypot2", hypot2,  1e-5,  1e-5);
  NumericalTest2("hypot2", hypot2,  0.0,   1.0);
  NumericalTest2("hypot2", hypot2,  1e-3,  1.0);
  NumericalTest2("hypot2", hypot2,  1e-3, -1.0);
  NumericalTest2("hypot2", hypot2, -1e-3,  1.0);
  NumericalTest2("hypot2", hypot2, -1e-3, -1.0);
  NumericalTest2("hypot2", hypot2,  1.0,   2.0);
  // clang-format on

  J zero = MakeJet(0.0, 2.0, 3.14);
  EXPECT_THAT(hypot(x, y), IsAlmostEqualTo(sqrt(x * x + y * y)));
  EXPECT_THAT(hypot(x, x), IsAlmostEqualTo(sqrt(2.0) * abs(x)));

  // The derivative is zero tangentially to the circle:
  EXPECT_THAT(hypot(MakeJet(2.0, 1.0, 1.0), MakeJet(2.0, 1.0, -1.0)),
              IsAlmostEqualTo(MakeJet(sqrt(8.0), std::sqrt(2.0), 0.0)));

  EXPECT_THAT(hypot(zero, x), IsAlmostEqualTo(x));
  EXPECT_THAT(hypot(y, zero), IsAlmostEqualTo(y));

  // hypot(x, 0, 0) == x, even when x * x underflows:
  EXPECT_EQ(
      std::numeric_limits<double>::min() * std::numeric_limits<double>::min(),
      0.0);  // Make sure it underflows
  J tiny = MakeJet(std::numeric_limits<double>::min(), 2.0, 3.14);
  EXPECT_THAT(hypot(tiny, J{0}), IsAlmostEqualTo(tiny));

  // hypot(x, 0, 0) == x, even when x * x overflows:
  EXPECT_EQ(
      std::numeric_limits<double>::max() * std::numeric_limits<double>::max(),
      std::numeric_limits<double>::infinity());
  J huge = MakeJet(std::numeric_limits<double>::max(), 2.0, 3.14);
  EXPECT_THAT(hypot(huge, J{0}), IsAlmostEqualTo(huge));
}

TEST(Jet, Hypot3) {
  J zero = MakeJet(0.0, 2.0, 3.14);

  // hypot(x, y, z) == sqrt(x^2 + y^2 + z^2)
  EXPECT_THAT(hypot(x, y, z), IsAlmostEqualTo(sqrt(x * x + y * y + z * z)));

  // hypot(x, x) == sqrt(3) * abs(x)
  EXPECT_THAT(hypot(x, x, x), IsAlmostEqualTo(sqrt(3.0) * abs(x)));

  // The derivative is zero tangentially to the circle:
  EXPECT_THAT(hypot(MakeJet(2.0, 1.0, 1.0),
                    MakeJet(2.0, 1.0, -1.0),
                    MakeJet(2.0, -1.0, 0.0)),
              IsAlmostEqualTo(MakeJet(sqrt(12.0), 1.0 / std::sqrt(3.0), 0.0)));

  EXPECT_THAT(hypot(x, zero, zero), IsAlmostEqualTo(x));
  EXPECT_THAT(hypot(zero, y, zero), IsAlmostEqualTo(y));
  EXPECT_THAT(hypot(zero, zero, z), IsAlmostEqualTo(z));
  EXPECT_THAT(hypot(x, y, z), IsAlmostEqualTo(hypot(hypot(x, y), z)));
  EXPECT_THAT(hypot(x, y, z), IsAlmostEqualTo(hypot(x, hypot(y, z))));

  // The following two tests are disabled because the three argument hypot is
  // broken in the libc++ shipped with CLANG as of January 2022.

#if !defined(_LIBCPP_VERSION)
  // hypot(x, 0, 0) == x, even when x * x underflows:
  EXPECT_EQ(
      std::numeric_limits<double>::min() * std::numeric_limits<double>::min(),
      0.0);  // Make sure it underflows
  J tiny = MakeJet(std::numeric_limits<double>::min(), 2.0, 3.14);
  EXPECT_THAT(hypot(tiny, J{0}, J{0}), IsAlmostEqualTo(tiny));

  // hypot(x, 0, 0) == x, even when x * x overflows:
  EXPECT_EQ(
      std::numeric_limits<double>::max() * std::numeric_limits<double>::max(),
      std::numeric_limits<double>::infinity());
  J huge = MakeJet(std::numeric_limits<double>::max(), 2.0, 3.14);
  EXPECT_THAT(hypot(huge, J{0}, J{0}), IsAlmostEqualTo(huge));
#endif
}

#ifdef CERES_HAS_CPP20

TEST(Jet, Lerp) {
  EXPECT_THAT(lerp(x, y, J{0}), IsAlmostEqualTo(x));
  EXPECT_THAT(lerp(x, y, J{1}), IsAlmostEqualTo(y));
  EXPECT_THAT(lerp(x, x, J{1}), IsAlmostEqualTo(x));
  EXPECT_THAT(lerp(y, y, J{0}), IsAlmostEqualTo(y));
  EXPECT_THAT(lerp(x, y, J{0.5}), IsAlmostEqualTo((x + y) / J{2.0}));
  EXPECT_THAT(lerp(x, y, J{2}), IsAlmostEqualTo(J{2.0} * y - x));
  EXPECT_THAT(lerp(x, y, J{-2}), IsAlmostEqualTo(J{3.0} * x - J{2} * y));
}

TEST(Jet, Midpoint) {
  EXPECT_THAT(midpoint(x, y), IsAlmostEqualTo((x + y) / J{2}));
  EXPECT_THAT(midpoint(x, x), IsAlmostEqualTo(x));

  {
    // midpoint(x, y) = (x + y) / 2 while avoiding overflow
    J x = MakeJet(std::numeric_limits<double>::min(), 1, 2);
    J y = MakeJet(std::numeric_limits<double>::max(), 3, 4);
    EXPECT_THAT(midpoint(x, y), IsAlmostEqualTo(x + (y - x) / J{2}));
  }

  {
    // midpoint(x, x) = x while avoiding overflow
    J x = MakeJet(std::numeric_limits<double>::max(),
                  std::numeric_limits<double>::max(),
                  std::numeric_limits<double>::max());
    EXPECT_THAT(midpoint(x, x), IsAlmostEqualTo(x));
  }

  {  // midpoint does not overflow for very large values
    constexpr double a = 0.75 * std::numeric_limits<double>::max();
    J x = MakeJet(a, a, -a);
    J y = MakeJet(a, a, a);
    EXPECT_THAT(midpoint(x, y), IsAlmostEqualTo(MakeJet(a, a, 0)));
  }
}

#endif  // defined(CERES_HAS_CPP20)

TEST(Jet, Fma) {
  J v = fma(x, y, z);
  J w = x * y + z;
  EXPECT_THAT(v, IsAlmostEqualTo(w));
}

TEST(Jet, FmaxJetWithJet) {
  Fenv env;
  // Clear all exceptions to ensure none are set by the following function
  // calls.
  std::feclearexcept(FE_ALL_EXCEPT);

  EXPECT_THAT(fmax(x, y), IsAlmostEqualTo(x));
  EXPECT_THAT(fmax(y, x), IsAlmostEqualTo(x));

  // Average the Jets on equality (of scalar parts).
  const J scalar_part_only_equal_to_x = J(x.a, 2 * x.v);
  const J average = (x + scalar_part_only_equal_to_x) * 0.5;
  EXPECT_THAT(fmax(x, scalar_part_only_equal_to_x), IsAlmostEqualTo(average));
  EXPECT_THAT(fmax(scalar_part_only_equal_to_x, x), IsAlmostEqualTo(average));

  // Follow convention of fmax(): treat NANs as missing values.
  const J nan_scalar_part(std::numeric_limits<double>::quiet_NaN(), 2 * x.v);
  EXPECT_THAT(fmax(x, nan_scalar_part), IsAlmostEqualTo(x));
  EXPECT_THAT(fmax(nan_scalar_part, x), IsAlmostEqualTo(x));

#ifndef CERES_NO_FENV_ACCESS
  EXPECT_EQ(std::fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT), 0);
#endif
}

TEST(Jet, FmaxJetWithScalar) {
  Fenv env;
  // Clear all exceptions to ensure none are set by the following function
  // calls.
  std::feclearexcept(FE_ALL_EXCEPT);

  EXPECT_THAT(fmax(x, y.a), IsAlmostEqualTo(x));
  EXPECT_THAT(fmax(y.a, x), IsAlmostEqualTo(x));
  EXPECT_THAT(fmax(y, x.a), IsAlmostEqualTo(J{x.a}));
  EXPECT_THAT(fmax(x.a, y), IsAlmostEqualTo(J{x.a}));

  // Average the Jet and scalar cast to a Jet on equality (of scalar parts).
  const J average = (x + J{x.a}) * 0.5;
  EXPECT_THAT(fmax(x, x.a), IsAlmostEqualTo(average));
  EXPECT_THAT(fmax(x.a, x), IsAlmostEqualTo(average));

  // Follow convention of fmax(): treat NANs as missing values.
  EXPECT_THAT(fmax(x, std::numeric_limits<double>::quiet_NaN()),
              IsAlmostEqualTo(x));
  EXPECT_THAT(fmax(std::numeric_limits<double>::quiet_NaN(), x),
              IsAlmostEqualTo(x));
  const J nan_scalar_part(std::numeric_limits<double>::quiet_NaN(), 2 * x.v);
  EXPECT_THAT(fmax(nan_scalar_part, x.a), IsAlmostEqualTo(J{x.a}));
  EXPECT_THAT(fmax(x.a, nan_scalar_part), IsAlmostEqualTo(J{x.a}));

#ifndef CERES_NO_FENV_ACCESS
  EXPECT_EQ(std::fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT), 0);
#endif
}

TEST(Jet, FminJetWithJet) {
  Fenv env;
  // Clear all exceptions to ensure none are set by the following function
  // calls.
  std::feclearexcept(FE_ALL_EXCEPT);

  EXPECT_THAT(fmin(x, y), IsAlmostEqualTo(y));
  EXPECT_THAT(fmin(y, x), IsAlmostEqualTo(y));

  // Average the Jets on equality (of scalar parts).
  const J scalar_part_only_equal_to_x = J(x.a, 2 * x.v);
  const J average = (x + scalar_part_only_equal_to_x) * 0.5;
  EXPECT_THAT(fmin(x, scalar_part_only_equal_to_x), IsAlmostEqualTo(average));
  EXPECT_THAT(fmin(scalar_part_only_equal_to_x, x), IsAlmostEqualTo(average));

  // Follow convention of fmin(): treat NANs as missing values.
  const J nan_scalar_part(std::numeric_limits<double>::quiet_NaN(), 2 * x.v);
  EXPECT_THAT(fmin(x, nan_scalar_part), IsAlmostEqualTo(x));
  EXPECT_THAT(fmin(nan_scalar_part, x), IsAlmostEqualTo(x));

#ifndef CERES_NO_FENV_ACCESS
  EXPECT_EQ(std::fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT), 0);
#endif
}

TEST(Jet, FminJetWithScalar) {
  Fenv env;
  // Clear all exceptions to ensure none are set by the following function
  // calls.
  std::feclearexcept(FE_ALL_EXCEPT);

  EXPECT_THAT(fmin(x, y.a), IsAlmostEqualTo(J{y.a}));
  EXPECT_THAT(fmin(y.a, x), IsAlmostEqualTo(J{y.a}));
  EXPECT_THAT(fmin(y, x.a), IsAlmostEqualTo(y));
  EXPECT_THAT(fmin(x.a, y), IsAlmostEqualTo(y));

  // Average the Jet and scalar cast to a Jet on equality (of scalar parts).
  const J average = (x + J{x.a}) * 0.5;
  EXPECT_THAT(fmin(x, x.a), IsAlmostEqualTo(average));
  EXPECT_THAT(fmin(x.a, x), IsAlmostEqualTo(average));

  // Follow convention of fmin(): treat NANs as missing values.
  EXPECT_THAT(fmin(x, std::numeric_limits<double>::quiet_NaN()),
              IsAlmostEqualTo(x));
  EXPECT_THAT(fmin(std::numeric_limits<double>::quiet_NaN(), x),
              IsAlmostEqualTo(x));
  const J nan_scalar_part(std::numeric_limits<double>::quiet_NaN(), 2 * x.v);
  EXPECT_THAT(fmin(nan_scalar_part, x.a), IsAlmostEqualTo(J{x.a}));
  EXPECT_THAT(fmin(x.a, nan_scalar_part), IsAlmostEqualTo(J{x.a}));

#ifndef CERES_NO_FENV_ACCESS
  EXPECT_EQ(std::fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT), 0);
#endif
}

TEST(Jet, Fdim) {
  Fenv env;
  // Clear all exceptions to ensure none are set by the following function
  // calls.
  std::feclearexcept(FE_ALL_EXCEPT);

  const J zero{};
  const J diff = x - y;
  const J diffx = x - J{y.a};
  const J diffy = J{x.a} - y;

  EXPECT_THAT(fdim(x, y), IsAlmostEqualTo(diff));
  EXPECT_THAT(fdim(y, x), IsAlmostEqualTo(zero));
  EXPECT_THAT(fdim(x, y.a), IsAlmostEqualTo(diffx));
  EXPECT_THAT(fdim(y.a, x), IsAlmostEqualTo(J{zero.a}));
  EXPECT_THAT(fdim(x.a, y), IsAlmostEqualTo(diffy));
  EXPECT_THAT(fdim(y, x.a), IsAlmostEqualTo(zero));
  EXPECT_TRUE(isnan(fdim(x, std::numeric_limits<J>::quiet_NaN())));
  EXPECT_TRUE(isnan(fdim(std::numeric_limits<J>::quiet_NaN(), x)));
  EXPECT_TRUE(isnan(fdim(x, std::numeric_limits<double>::quiet_NaN())));
  EXPECT_TRUE(isnan(fdim(std::numeric_limits<double>::quiet_NaN(), x)));

#ifndef CERES_NO_FENV_ACCESS
  EXPECT_EQ(std::fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT), 0);
#endif
}

TEST(Jet, CopySign) {
  {  // copysign(x, +1)
    J z = copysign(x, J{+1});
    EXPECT_THAT(z, IsAlmostEqualTo(x));
    EXPECT_TRUE(isfinite(z.v[0])) << z;
    EXPECT_TRUE(isfinite(z.v[1])) << z;
  }
  {  // copysign(x, -1)
    J z = copysign(x, J{-1});
    EXPECT_THAT(z, IsAlmostEqualTo(-x));
    EXPECT_TRUE(isfinite(z.v[0])) << z;
    EXPECT_TRUE(isfinite(z.v[1])) << z;
  }
  {  // copysign(-x, +1)

    J z = copysign(-x, J{+1});
    EXPECT_THAT(z, IsAlmostEqualTo(x));
    EXPECT_TRUE(isfinite(z.v[0])) << z;
    EXPECT_TRUE(isfinite(z.v[1])) << z;
  }
  {  // copysign(-x, -1)
    J z = copysign(-x, J{-1});
    EXPECT_THAT(z, IsAlmostEqualTo(-x));
    EXPECT_TRUE(isfinite(z.v[0])) << z;
    EXPECT_TRUE(isfinite(z.v[1])) << z;
  }
  {  // copysign(-0, +1)
    J z = copysign(MakeJet(-0, 1, 2), J{+1});
    EXPECT_THAT(z, IsAlmostEqualTo(MakeJet(+0, 1, 2)));
    EXPECT_FALSE(std::signbit(z.a)) << z;
    EXPECT_TRUE(isfinite(z.v[0])) << z;
    EXPECT_TRUE(isfinite(z.v[1])) << z;
  }
  {  // copysign(-0, -1)
    J z = copysign(MakeJet(-0, 1, 2), J{-1});
    EXPECT_THAT(z, IsAlmostEqualTo(MakeJet(-0, -1, -2)));
    EXPECT_TRUE(std::signbit(z.a)) << z;
    EXPECT_TRUE(isfinite(z.v[0])) << z;
    EXPECT_TRUE(isfinite(z.v[1])) << z;
  }
  {  // copysign(+0, -1)
    J z = copysign(MakeJet(+0, 1, 2), J{-1});
    EXPECT_THAT(z, IsAlmostEqualTo(MakeJet(-0, -1, -2)));
    EXPECT_TRUE(std::signbit(z.a)) << z;
    EXPECT_TRUE(isfinite(z.v[0])) << z;
    EXPECT_TRUE(isfinite(z.v[1])) << z;
  }
  {  // copysign(+0, +1)
    J z = copysign(MakeJet(+0, 1, 2), J{+1});
    EXPECT_THAT(z, IsAlmostEqualTo(MakeJet(+0, 1, 2)));
    EXPECT_FALSE(std::signbit(z.a)) << z;
    EXPECT_TRUE(isfinite(z.v[0])) << z;
    EXPECT_TRUE(isfinite(z.v[1])) << z;
  }
  {  // copysign(+0, +0)
    J z = copysign(MakeJet(+0, 1, 2), J{+0});
    EXPECT_FALSE(std::signbit(z.a)) << z;
    EXPECT_TRUE(isnan(z.v[0])) << z;
    EXPECT_TRUE(isnan(z.v[1])) << z;
  }
  {  // copysign(+0, -0)
    J z = copysign(MakeJet(+0, 1, 2), J{-0});
    EXPECT_FALSE(std::signbit(z.a)) << z;
    EXPECT_TRUE(isnan(z.v[0])) << z;
    EXPECT_TRUE(isnan(z.v[1])) << z;
  }
  {  // copysign(-0, +0)
    J z = copysign(MakeJet(-0, 1, 2), J{+0});
    EXPECT_FALSE(std::signbit(z.a)) << z;
    EXPECT_TRUE(isnan(z.v[0])) << z;
    EXPECT_TRUE(isnan(z.v[1])) << z;
  }
  {  // copysign(-0, -0)
    J z = copysign(MakeJet(-0, 1, 2), J{-0});
    EXPECT_FALSE(std::signbit(z.a)) << z;
    EXPECT_TRUE(isnan(z.v[0])) << z;
    EXPECT_TRUE(isnan(z.v[1])) << z;
  }
  {  // copysign(1, -nan)
    J z = copysign(MakeJet(1, 2, 3),
                   -J{std::numeric_limits<double>::quiet_NaN()});
    EXPECT_TRUE(std::signbit(z.a)) << z;
    EXPECT_TRUE(std::signbit(z.v[0])) << z;
    EXPECT_TRUE(std::signbit(z.v[1])) << z;
    EXPECT_FALSE(isnan(z.v[0])) << z;
    EXPECT_FALSE(isnan(z.v[1])) << z;
  }
  {  // copysign(1, +nan)
    J z = copysign(MakeJet(1, 2, 3),
                   +J{std::numeric_limits<double>::quiet_NaN()});
    EXPECT_FALSE(std::signbit(z.a)) << z;
    EXPECT_FALSE(std::signbit(z.v[0])) << z;
    EXPECT_FALSE(std::signbit(z.v[1])) << z;
    EXPECT_FALSE(isnan(z.v[0])) << z;
    EXPECT_FALSE(isnan(z.v[1])) << z;
  }
}

TEST(Jet, JetsInEigenMatrices) {
  J x = MakeJet(2.3, -2.7, 1e-3);
  J y = MakeJet(1.7, 0.5, 1e+2);
  J z = MakeJet(5.3, -4.7, 1e-3);
  J w = MakeJet(9.7, 1.5, 10.1);

  Eigen::Matrix<J, 2, 2> M;
  Eigen::Matrix<J, 2, 1> v, r1, r2;

  M << x, y, z, w;
  v << x, z;

  // M * v == (v^T * M^T)^T
  r1 = M * v;
  r2 = (v.transpose() * M.transpose()).transpose();

  EXPECT_THAT(r1(0), IsAlmostEqualTo(r2(0)));
  EXPECT_THAT(r1(1), IsAlmostEqualTo(r2(1)));
}

TEST(Jet, ScalarComparison) {
  Jet<double, 1> zero{0.0};
  zero.v << std::numeric_limits<double>::infinity();

  Jet<double, 1> one{1.0};
  one.v << std::numeric_limits<double>::quiet_NaN();

  Jet<double, 1> two{2.0};
  two.v << std::numeric_limits<double>::min() / 2;

  Jet<double, 1> three{3.0};

  auto inf = std::numeric_limits<Jet<double, 1>>::infinity();
  auto nan = std::numeric_limits<Jet<double, 1>>::quiet_NaN();
  inf.v << 1.2;
  nan.v << 3.4;

  std::feclearexcept(FE_ALL_EXCEPT);

  EXPECT_FALSE(islessgreater(zero, zero));
  EXPECT_FALSE(islessgreater(zero, zero.a));
  EXPECT_FALSE(islessgreater(zero.a, zero));

  EXPECT_TRUE(isgreaterequal(three, three));
  EXPECT_TRUE(isgreaterequal(three, three.a));
  EXPECT_TRUE(isgreaterequal(three.a, three));

  EXPECT_TRUE(isgreater(three, two));
  EXPECT_TRUE(isgreater(three, two.a));
  EXPECT_TRUE(isgreater(three.a, two));

  EXPECT_TRUE(islessequal(one, one));
  EXPECT_TRUE(islessequal(one, one.a));
  EXPECT_TRUE(islessequal(one.a, one));

  EXPECT_TRUE(isless(one, two));
  EXPECT_TRUE(isless(one, two.a));
  EXPECT_TRUE(isless(one.a, two));

  EXPECT_FALSE(isunordered(inf, one));
  EXPECT_FALSE(isunordered(inf, one.a));
  EXPECT_FALSE(isunordered(inf.a, one));

  EXPECT_TRUE(isunordered(nan, two));
  EXPECT_TRUE(isunordered(nan, two.a));
  EXPECT_TRUE(isunordered(nan.a, two));

  EXPECT_TRUE(isunordered(inf, nan));
  EXPECT_TRUE(isunordered(inf, nan.a));
  EXPECT_TRUE(isunordered(inf.a, nan.a));

  EXPECT_EQ(std::fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT), 0);
}

TEST(Jet, Nested2XScalarComparison) {
  Jet<J0d, 1> zero{J0d{0.0}};
  zero.v << std::numeric_limits<J0d>::infinity();

  Jet<J0d, 1> one{J0d{1.0}};
  one.v << std::numeric_limits<J0d>::quiet_NaN();

  Jet<J0d, 1> two{J0d{2.0}};
  two.v << std::numeric_limits<J0d>::min() / J0d{2};

  Jet<J0d, 1> three{J0d{3.0}};

  auto inf = std::numeric_limits<Jet<J0d, 1>>::infinity();
  auto nan = std::numeric_limits<Jet<J0d, 1>>::quiet_NaN();
  inf.v << J0d{1.2};
  nan.v << J0d{3.4};

  std::feclearexcept(FE_ALL_EXCEPT);

  EXPECT_FALSE(islessgreater(zero, zero));
  EXPECT_FALSE(islessgreater(zero, zero.a));
  EXPECT_FALSE(islessgreater(zero.a, zero));
  EXPECT_FALSE(islessgreater(zero, zero.a.a));
  EXPECT_FALSE(islessgreater(zero.a.a, zero));

  EXPECT_TRUE(isgreaterequal(three, three));
  EXPECT_TRUE(isgreaterequal(three, three.a));
  EXPECT_TRUE(isgreaterequal(three.a, three));
  EXPECT_TRUE(isgreaterequal(three, three.a.a));
  EXPECT_TRUE(isgreaterequal(three.a.a, three));

  EXPECT_TRUE(isgreater(three, two));
  EXPECT_TRUE(isgreater(three, two.a));
  EXPECT_TRUE(isgreater(three.a, two));
  EXPECT_TRUE(isgreater(three, two.a.a));
  EXPECT_TRUE(isgreater(three.a.a, two));

  EXPECT_TRUE(islessequal(one, one));
  EXPECT_TRUE(islessequal(one, one.a));
  EXPECT_TRUE(islessequal(one.a, one));
  EXPECT_TRUE(islessequal(one, one.a.a));
  EXPECT_TRUE(islessequal(one.a.a, one));

  EXPECT_TRUE(isless(one, two));
  EXPECT_TRUE(isless(one, two.a));
  EXPECT_TRUE(isless(one.a, two));
  EXPECT_TRUE(isless(one, two.a.a));
  EXPECT_TRUE(isless(one.a.a, two));

  EXPECT_FALSE(isunordered(inf, one));
  EXPECT_FALSE(isunordered(inf, one.a));
  EXPECT_FALSE(isunordered(inf.a, one));
  EXPECT_FALSE(isunordered(inf, one.a.a));
  EXPECT_FALSE(isunordered(inf.a.a, one));

  EXPECT_TRUE(isunordered(nan, two));
  EXPECT_TRUE(isunordered(nan, two.a));
  EXPECT_TRUE(isunordered(nan.a, two));
  EXPECT_TRUE(isunordered(nan, two.a.a));
  EXPECT_TRUE(isunordered(nan.a.a, two));

  EXPECT_TRUE(isunordered(inf, nan));
  EXPECT_TRUE(isunordered(inf, nan.a));
  EXPECT_TRUE(isunordered(inf.a, nan));
  EXPECT_TRUE(isunordered(inf, nan.a.a));
  EXPECT_TRUE(isunordered(inf.a.a, nan));

  EXPECT_EQ(std::fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT), 0);
}

TEST(JetTraitsTest, ClassificationNaN) {
  Jet<double, 1> a(std::numeric_limits<double>::quiet_NaN());
  a.v << std::numeric_limits<double>::infinity();
  EXPECT_EQ(fpclassify(a), FP_NAN);
  EXPECT_FALSE(isfinite(a));
  EXPECT_FALSE(isinf(a));
  EXPECT_FALSE(isnormal(a));
  EXPECT_FALSE(signbit(a));
  EXPECT_TRUE(isnan(a));
}

TEST(JetTraitsTest, ClassificationInf) {
  Jet<double, 1> a(-std::numeric_limits<double>::infinity());
  a.v << std::numeric_limits<double>::quiet_NaN();
  EXPECT_EQ(fpclassify(a), FP_INFINITE);
  EXPECT_FALSE(isfinite(a));
  EXPECT_FALSE(isnan(a));
  EXPECT_FALSE(isnormal(a));
  EXPECT_TRUE(signbit(a));
  EXPECT_TRUE(isinf(a));
}

TEST(JetTraitsTest, ClassificationFinite) {
  Jet<double, 1> a(-5.5);
  a.v << std::numeric_limits<double>::quiet_NaN();
  EXPECT_EQ(fpclassify(a), FP_NORMAL);
  EXPECT_FALSE(isinf(a));
  EXPECT_FALSE(isnan(a));
  EXPECT_TRUE(signbit(a));
  EXPECT_TRUE(isfinite(a));
  EXPECT_TRUE(isnormal(a));
}

TEST(JetTraitsTest, ClassificationScalar) {
  EXPECT_EQ(fpclassify(J0d{+0.0}), FP_ZERO);
  EXPECT_EQ(fpclassify(J0d{-0.0}), FP_ZERO);
  EXPECT_EQ(fpclassify(J0d{1.234}), FP_NORMAL);
  EXPECT_EQ(fpclassify(J0d{std::numeric_limits<double>::min() / 2}),
            FP_SUBNORMAL);
  EXPECT_EQ(fpclassify(J0d{std::numeric_limits<double>::quiet_NaN()}), FP_NAN);
}

TEST(JetTraitsTest, Nested2XClassificationScalar) {
  EXPECT_EQ(fpclassify(J0<J0d>{J0d{+0.0}}), FP_ZERO);
  EXPECT_EQ(fpclassify(J0<J0d>{J0d{-0.0}}), FP_ZERO);
  EXPECT_EQ(fpclassify(J0<J0d>{J0d{1.234}}), FP_NORMAL);
  EXPECT_EQ(fpclassify(J0<J0d>{J0d{std::numeric_limits<double>::min() / 2}}),
            FP_SUBNORMAL);
  EXPECT_EQ(fpclassify(J0<J0d>{J0d{std::numeric_limits<double>::quiet_NaN()}}),
            FP_NAN);
}

// The following test ensures that Jets have all the appropriate Eigen
// related traits so that they can be used as part of matrix
// decompositions.
TEST(Jet, FullRankEigenLLTSolve) {
  Eigen::Matrix<J, 3, 3> A;
  Eigen::Matrix<J, 3, 1> b, x;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      A(i, j) = MakeJet(0.0, i, j * j);
    }
    b(i) = MakeJet(i, i, i);
    x(i) = MakeJet(0.0, 0.0, 0.0);
    A(i, i) = MakeJet(1.0, i, i * i);
  }
  x = A.llt().solve(b);
  for (int i = 0; i < 3; ++i) {
    EXPECT_EQ(x(i).a, b(i).a);
  }
}

TEST(Jet, FullRankEigenLDLTSolve) {
  Eigen::Matrix<J, 3, 3> A;
  Eigen::Matrix<J, 3, 1> b, x;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      A(i, j) = MakeJet(0.0, i, j * j);
    }
    b(i) = MakeJet(i, i, i);
    x(i) = MakeJet(0.0, 0.0, 0.0);
    A(i, i) = MakeJet(1.0, i, i * i);
  }
  x = A.ldlt().solve(b);
  for (int i = 0; i < 3; ++i) {
    EXPECT_EQ(x(i).a, b(i).a);
  }
}

TEST(Jet, FullRankEigenLUSolve) {
  Eigen::Matrix<J, 3, 3> A;
  Eigen::Matrix<J, 3, 1> b, x;
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      A(i, j) = MakeJet(0.0, i, j * j);
    }
    b(i) = MakeJet(i, i, i);
    x(i) = MakeJet(0.0, 0.0, 0.0);
    A(i, i) = MakeJet(1.0, i, i * i);
  }

  x = A.lu().solve(b);
  for (int i = 0; i < 3; ++i) {
    EXPECT_EQ(x(i).a, b(i).a);
  }
}

// ScalarBinaryOpTraits is only supported on Eigen versions >= 3.3
TEST(JetTraitsTest, MatrixScalarUnaryOps) {
  const J x = MakeJet(2.3, -2.7, 1e-3);
  const J y = MakeJet(1.7, 0.5, 1e+2);
  Eigen::Matrix<J, 2, 1> a;
  a << x, y;

  const J sum = a.sum();
  const J sum2 = a(0) + a(1);
  EXPECT_THAT(sum, IsAlmostEqualTo(sum2));
}

TEST(JetTraitsTest, MatrixScalarBinaryOps) {
  const J x = MakeJet(2.3, -2.7, 1e-3);
  const J y = MakeJet(1.7, 0.5, 1e+2);
  const J z = MakeJet(5.3, -4.7, 1e-3);
  const J w = MakeJet(9.7, 1.5, 10.1);

  Eigen::Matrix<J, 2, 2> M;
  Eigen::Vector2d v;

  M << x, y, z, w;
  v << 0.6, -2.1;

  // M * v == M * v.cast<J>().
  const Eigen::Matrix<J, 2, 1> r1 = M * v;
  const Eigen::Matrix<J, 2, 1> r2 = M * v.cast<J>();

  EXPECT_THAT(r1(0), IsAlmostEqualTo(r2(0)));
  EXPECT_THAT(r1(1), IsAlmostEqualTo(r2(1)));

  // M * a == M * T(a).
  const double a = 3.1;
  const Eigen::Matrix<J, 2, 2> r3 = M * a;
  const Eigen::Matrix<J, 2, 2> r4 = M * J(a);

  EXPECT_THAT(r3(0, 0), IsAlmostEqualTo(r4(0, 0)));
  EXPECT_THAT(r3(0, 1), IsAlmostEqualTo(r4(0, 1)));
  EXPECT_THAT(r3(1, 0), IsAlmostEqualTo(r4(1, 0)));
  EXPECT_THAT(r3(1, 1), IsAlmostEqualTo(r4(1, 1)));
}

TEST(JetTraitsTest, ArrayScalarUnaryOps) {
  const J x = MakeJet(2.3, -2.7, 1e-3);
  const J y = MakeJet(1.7, 0.5, 1e+2);
  Eigen::Array<J, 2, 1> a;
  a << x, y;

  const J sum = a.sum();
  const J sum2 = a(0) + a(1);
  EXPECT_THAT(sum, sum2);
}

TEST(JetTraitsTest, ArrayScalarBinaryOps) {
  const J x = MakeJet(2.3, -2.7, 1e-3);
  const J y = MakeJet(1.7, 0.5, 1e+2);

  Eigen::Array<J, 2, 1> a;
  Eigen::Array2d b;

  a << x, y;
  b << 0.6, -2.1;

  // a * b == a * b.cast<T>()
  const Eigen::Array<J, 2, 1> r1 = a * b;
  const Eigen::Array<J, 2, 1> r2 = a * b.cast<J>();

  EXPECT_THAT(r1(0), r2(0));
  EXPECT_THAT(r1(1), r2(1));

  // a * c == a * T(c).
  const double c = 3.1;
  const Eigen::Array<J, 2, 1> r3 = a * c;
  const Eigen::Array<J, 2, 1> r4 = a * J(c);

  EXPECT_THAT(r3(0), r3(0));
  EXPECT_THAT(r4(1), r4(1));
}

TEST(Jet, Nested3X) {
  using JJ = Jet<J, 2>;
  using JJJ = Jet<JJ, 2>;

  JJJ x;
  x.a = JJ(J(1, 0), 0);
  x.v[0] = JJ(J(1));

  JJJ y = x * x * x;

  ExpectClose(y.a.a.a, 1, kTolerance);
  ExpectClose(y.v[0].a.a, 3., kTolerance);
  ExpectClose(y.v[0].v[0].a, 6., kTolerance);
  ExpectClose(y.v[0].v[0].v[0], 6., kTolerance);

  JJJ e = exp(x);

  ExpectClose(e.a.a.a, kE, kTolerance);
  ExpectClose(e.v[0].a.a, kE, kTolerance);
  ExpectClose(e.v[0].v[0].a, kE, kTolerance);
  ExpectClose(e.v[0].v[0].v[0], kE, kTolerance);
}

#if GTEST_HAS_TYPED_TEST

using Types = testing::Types<std::int16_t,
                             std::uint16_t,
                             std::int32_t,
                             std::uint32_t,
                             std::int64_t,
                             std::uint64_t,
                             float,
                             double,
                             long double>;

template <typename T>
class JetTest : public testing::Test {};

TYPED_TEST_SUITE(JetTest, Types);

TYPED_TEST(JetTest, Comparison) {
  using Scalar = TypeParam;

  EXPECT_EQ(J0<Scalar>{0}, J0<Scalar>{0});
  EXPECT_GE(J0<Scalar>{3}, J0<Scalar>{3});
  EXPECT_GT(J0<Scalar>{3}, J0<Scalar>{2});
  EXPECT_LE(J0<Scalar>{1}, J0<Scalar>{1});
  EXPECT_LT(J0<Scalar>{1}, J0<Scalar>{2});
  EXPECT_NE(J0<Scalar>{1}, J0<Scalar>{2});
}

TYPED_TEST(JetTest, ScalarComparison) {
  using Scalar = TypeParam;

  EXPECT_EQ(J0d{0.0}, Scalar{0});
  EXPECT_GE(J0d{3.0}, Scalar{3});
  EXPECT_GT(J0d{3.0}, Scalar{2});
  EXPECT_LE(J0d{1.0}, Scalar{1});
  EXPECT_LT(J0d{1.0}, Scalar{2});
  EXPECT_NE(J0d{1.0}, Scalar{2});

  EXPECT_EQ(Scalar{0}, J0d{0.0});
  EXPECT_GE(Scalar{1}, J0d{1.0});
  EXPECT_GT(Scalar{2}, J0d{1.0});
  EXPECT_LE(Scalar{3}, J0d{3.0});
  EXPECT_LT(Scalar{2}, J0d{3.0});
  EXPECT_NE(Scalar{2}, J0d{1.0});
}

TYPED_TEST(JetTest, Nested2XComparison) {
  using Scalar = TypeParam;

  EXPECT_EQ(J0<J0d>{J0d{0.0}}, Scalar{0});
  EXPECT_GE(J0<J0d>{J0d{3.0}}, Scalar{3});
  EXPECT_GT(J0<J0d>{J0d{3.0}}, Scalar{2});
  EXPECT_LE(J0<J0d>{J0d{1.0}}, Scalar{1});
  EXPECT_LT(J0<J0d>{J0d{1.0}}, Scalar{2});
  EXPECT_NE(J0<J0d>{J0d{1.0}}, Scalar{2});

  EXPECT_EQ(Scalar{0}, J0<J0d>{J0d{0.0}});
  EXPECT_GE(Scalar{1}, J0<J0d>{J0d{1.0}});
  EXPECT_GT(Scalar{2}, J0<J0d>{J0d{1.0}});
  EXPECT_LE(Scalar{3}, J0<J0d>{J0d{3.0}});
  EXPECT_LT(Scalar{2}, J0<J0d>{J0d{3.0}});
  EXPECT_NE(Scalar{2}, J0<J0d>{J0d{1.0}});
}

TYPED_TEST(JetTest, Nested3XComparison) {
  using Scalar = TypeParam;

  EXPECT_EQ(J0<J0<J0d>>{J0<J0d>{J0d{0.0}}}, Scalar{0});
  EXPECT_GE(J0<J0<J0d>>{J0<J0d>{J0d{3.0}}}, Scalar{3});
  EXPECT_GT(J0<J0<J0d>>{J0<J0d>{J0d{3.0}}}, Scalar{2});
  EXPECT_LE(J0<J0<J0d>>{J0<J0d>{J0d{1.0}}}, Scalar{1});
  EXPECT_LT(J0<J0<J0d>>{J0<J0d>{J0d{1.0}}}, Scalar{2});
  EXPECT_NE(J0<J0<J0d>>{J0<J0d>{J0d{1.0}}}, Scalar{2});

  EXPECT_EQ(Scalar{0}, J0<J0<J0d>>{J0<J0d>{J0d{0.0}}});
  EXPECT_GE(Scalar{1}, J0<J0<J0d>>{J0<J0d>{J0d{1.0}}});
  EXPECT_GT(Scalar{2}, J0<J0<J0d>>{J0<J0d>{J0d{1.0}}});
  EXPECT_LE(Scalar{3}, J0<J0<J0d>>{J0<J0d>{J0d{3.0}}});
  EXPECT_LT(Scalar{2}, J0<J0<J0d>>{J0<J0d>{J0d{3.0}}});
  EXPECT_NE(Scalar{2}, J0<J0<J0d>>{J0<J0d>{J0d{1.0}}});
}

#endif  // GTEST_HAS_TYPED_TEST

}  // namespace ceres::internal

#ifdef _MSC_VER
#pragma float_control(pop)
#endif
