Skip to content

Conversation

@cjdb
Copy link
Contributor

@cjdb cjdb commented Jan 13, 2025

This increases test coverage for std::complex, and improves verifying improvements to complex to non-double types.

This increases test coverage for `std::complex`, and improves verifying
improvements to `complex` to non-double types.
@cjdb cjdb requested a review from a team as a code owner January 13, 2025 22:25
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 13, 2025

@llvm/pr-subscribers-libcxx

Author: Christopher Di Bella (cjdb)

Changes

This increases test coverage for std::complex, and improves verifying improvements to complex to non-double types.


Patch is 133.42 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/122809.diff

28 Files Affected:

  • (modified) libcxx/test/std/numerics/complex.number/cases.h (+165-166)
  • (modified) libcxx/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp (+13-9)
  • (modified) libcxx/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp (+77-80)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/acos.pass.cpp (+75-97)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp (+84-108)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp (+56-76)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp (+63-85)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/atan.pass.cpp (+24-25)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/atanh.pass.cpp (+67-89)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/cos.pass.cpp (+23-24)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/cosh.pass.cpp (+57-74)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp (+52-75)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/log.pass.cpp (+70-89)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/log10.pass.cpp (+22-23)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/pow_complex_complex.pass.cpp (+24-26)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/pow_complex_scalar.pass.cpp (+22-24)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/pow_scalar_complex.pass.cpp (+22-24)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/sin.pass.cpp (+24-25)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/sinh.pass.cpp (+60-75)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp (+67-65)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/tan.pass.cpp (+24-25)
  • (modified) libcxx/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp (+45-57)
  • (modified) libcxx/test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp (+27-27)
  • (modified) libcxx/test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp (+75-97)
  • (modified) libcxx/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp (+27-27)
  • (modified) libcxx/test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp (+45-57)
  • (modified) libcxx/test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp (+26-26)
  • (modified) libcxx/utils/libcxx/test/params.py (+2-1)
diff --git a/libcxx/test/std/numerics/complex.number/cases.h b/libcxx/test/std/numerics/complex.number/cases.h
index b360e1423ff576..69059bdebdcfed 100644
--- a/libcxx/test/std/numerics/complex.number/cases.h
+++ b/libcxx/test/std/numerics/complex.number/cases.h
@@ -15,181 +15,182 @@
 
 #include <cassert>
 #include <complex>
+#include <limits>
 #include <type_traits>
 
 #include "test_macros.h"
 
-TEST_CONSTEXPR_CXX20 const std::complex<double> testcases[] =
-{
-    std::complex<double>( 1.e-6,  1.e-6),
-    std::complex<double>(-1.e-6,  1.e-6),
-    std::complex<double>(-1.e-6, -1.e-6),
-    std::complex<double>( 1.e-6, -1.e-6),
+template <class T>
+TEST_CONSTEXPR_CXX20 const std::complex<T> testcases[] = {
+    std::complex<T>(+1.e-6, +1.e-6),
+    std::complex<T>(-1.e-6, +1.e-6),
+    std::complex<T>(-1.e-6, -1.e-6),
+    std::complex<T>(+1.e-6, -1.e-6),
 
-    std::complex<double>( 1.e+6,  1.e-6),
-    std::complex<double>(-1.e+6,  1.e-6),
-    std::complex<double>(-1.e+6, -1.e-6),
-    std::complex<double>( 1.e+6, -1.e-6),
+    std::complex<T>(+1.e+6, +1.e-6),
+    std::complex<T>(-1.e+6, +1.e-6),
+    std::complex<T>(-1.e+6, -1.e-6),
+    std::complex<T>(+1.e+6, -1.e-6),
 
-    std::complex<double>( 1.e-6,  1.e+6),
-    std::complex<double>(-1.e-6,  1.e+6),
-    std::complex<double>(-1.e-6, -1.e+6),
-    std::complex<double>( 1.e-6, -1.e+6),
+    std::complex<T>(+1.e-6, +1.e+6),
+    std::complex<T>(-1.e-6, +1.e+6),
+    std::complex<T>(-1.e-6, -1.e+6),
+    std::complex<T>(+1.e-6, -1.e+6),
 
-    std::complex<double>( 1.e+6,  1.e+6),
-    std::complex<double>(-1.e+6,  1.e+6),
-    std::complex<double>(-1.e+6, -1.e+6),
-    std::complex<double>( 1.e+6, -1.e+6),
+    std::complex<T>(+1.e+6, +1.e+6),
+    std::complex<T>(-1.e+6, +1.e+6),
+    std::complex<T>(-1.e+6, -1.e+6),
+    std::complex<T>(+1.e+6, -1.e+6),
 
-    std::complex<double>(-0, -1.e-6),
-    std::complex<double>(-0,  1.e-6),
-    std::complex<double>(-0,  1.e+6),
-    std::complex<double>(-0, -1.e+6),
-    std::complex<double>( 0, -1.e-6),
-    std::complex<double>( 0,  1.e-6),
-    std::complex<double>( 0,  1.e+6),
-    std::complex<double>( 0, -1.e+6),
+    std::complex<T>(-0.0, -1.e-6),
+    std::complex<T>(-0.0, +1.e-6),
+    std::complex<T>(-0.0, +1.e+6),
+    std::complex<T>(-0.0, -1.e+6),
+    std::complex<T>(+0.0, -1.e-6),
+    std::complex<T>(+0.0, +1.e-6),
+    std::complex<T>(+0.0, +1.e+6),
+    std::complex<T>(+0.0, -1.e+6),
 
-    std::complex<double>(-1.e-6, -0),
-    std::complex<double>( 1.e-6, -0),
-    std::complex<double>( 1.e+6, -0),
-    std::complex<double>(-1.e+6, -0),
-    std::complex<double>(-1.e-6,  0),
-    std::complex<double>( 1.e-6,  0),
-    std::complex<double>( 1.e+6,  0),
-    std::complex<double>(-1.e+6,  0),
+    std::complex<T>(-1.e-6, -0.0),
+    std::complex<T>(+1.e-6, -0.0),
+    std::complex<T>(+1.e+6, -0.0),
+    std::complex<T>(-1.e+6, -0.0),
+    std::complex<T>(-1.e-6, +0.0),
+    std::complex<T>(+1.e-6, +0.0),
+    std::complex<T>(+1.e+6, +0.0),
+    std::complex<T>(-1.e+6, +0.0),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(-2, std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(-1, std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(-0.5, std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(-0., std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(+0., std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(0.5, std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(1, std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(2, std::numeric_limits<double>::quiet_NaN()),
-    std::complex<double>(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::quiet_NaN()),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(-2, std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(-1, std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(-0.5, std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(-0., std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(+0., std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(0.5, std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(1, std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(2, std::numeric_limits<T>::quiet_NaN()),
+    std::complex<T>(std::numeric_limits<T>::infinity(), std::numeric_limits<T>::quiet_NaN()),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), -std::numeric_limits<double>::infinity()),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity()),
-    std::complex<double>(-2, -std::numeric_limits<double>::infinity()),
-    std::complex<double>(-1, -std::numeric_limits<double>::infinity()),
-    std::complex<double>(-0.5, -std::numeric_limits<double>::infinity()),
-    std::complex<double>(-0., -std::numeric_limits<double>::infinity()),
-    std::complex<double>(+0., -std::numeric_limits<double>::infinity()),
-    std::complex<double>(0.5, -std::numeric_limits<double>::infinity()),
-    std::complex<double>(1, -std::numeric_limits<double>::infinity()),
-    std::complex<double>(2, -std::numeric_limits<double>::infinity()),
-    std::complex<double>(std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity()),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), -std::numeric_limits<T>::infinity()),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity()),
+    std::complex<T>(-2, -std::numeric_limits<T>::infinity()),
+    std::complex<T>(-1, -std::numeric_limits<T>::infinity()),
+    std::complex<T>(-0.5, -std::numeric_limits<T>::infinity()),
+    std::complex<T>(-0., -std::numeric_limits<T>::infinity()),
+    std::complex<T>(+0., -std::numeric_limits<T>::infinity()),
+    std::complex<T>(0.5, -std::numeric_limits<T>::infinity()),
+    std::complex<T>(1, -std::numeric_limits<T>::infinity()),
+    std::complex<T>(2, -std::numeric_limits<T>::infinity()),
+    std::complex<T>(std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity()),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), -2),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), -2),
-    std::complex<double>(-2, -2),
-    std::complex<double>(-1, -2),
-    std::complex<double>(-0.5, -2),
-    std::complex<double>(-0., -2),
-    std::complex<double>(+0., -2),
-    std::complex<double>(0.5, -2),
-    std::complex<double>(1, -2),
-    std::complex<double>(2, -2),
-    std::complex<double>(std::numeric_limits<double>::infinity(), -2),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), -2),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), -2),
+    std::complex<T>(-2, -2),
+    std::complex<T>(-1, -2),
+    std::complex<T>(-0.5, -2),
+    std::complex<T>(-0., -2),
+    std::complex<T>(+0., -2),
+    std::complex<T>(0.5, -2),
+    std::complex<T>(1, -2),
+    std::complex<T>(2, -2),
+    std::complex<T>(std::numeric_limits<T>::infinity(), -2),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), -1),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), -1),
-    std::complex<double>(-2, -1),
-    std::complex<double>(-1, -1),
-    std::complex<double>(-0.5, -1),
-    std::complex<double>(-0., -1),
-    std::complex<double>(+0., -1),
-    std::complex<double>(0.5, -1),
-    std::complex<double>(1, -1),
-    std::complex<double>(2, -1),
-    std::complex<double>(std::numeric_limits<double>::infinity(), -1),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), -1),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), -1),
+    std::complex<T>(-2, -1),
+    std::complex<T>(-1, -1),
+    std::complex<T>(-0.5, -1),
+    std::complex<T>(-0., -1),
+    std::complex<T>(+0., -1),
+    std::complex<T>(0.5, -1),
+    std::complex<T>(1, -1),
+    std::complex<T>(2, -1),
+    std::complex<T>(std::numeric_limits<T>::infinity(), -1),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), -0.5),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), -0.5),
-    std::complex<double>(-2, -0.5),
-    std::complex<double>(-1, -0.5),
-    std::complex<double>(-0.5, -0.5),
-    std::complex<double>(-0., -0.5),
-    std::complex<double>(+0., -0.5),
-    std::complex<double>(0.5, -0.5),
-    std::complex<double>(1, -0.5),
-    std::complex<double>(2, -0.5),
-    std::complex<double>(std::numeric_limits<double>::infinity(), -0.5),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), -0.5),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), -0.5),
+    std::complex<T>(-2, -0.5),
+    std::complex<T>(-1, -0.5),
+    std::complex<T>(-0.5, -0.5),
+    std::complex<T>(-0., -0.5),
+    std::complex<T>(+0., -0.5),
+    std::complex<T>(0.5, -0.5),
+    std::complex<T>(1, -0.5),
+    std::complex<T>(2, -0.5),
+    std::complex<T>(std::numeric_limits<T>::infinity(), -0.5),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), -0.),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), -0.),
-    std::complex<double>(-2, -0.),
-    std::complex<double>(-1, -0.),
-    std::complex<double>(-0.5, -0.),
-    std::complex<double>(-0., -0.),
-    std::complex<double>(+0., -0.),
-    std::complex<double>(0.5, -0.),
-    std::complex<double>(1, -0.),
-    std::complex<double>(2, -0.),
-    std::complex<double>(std::numeric_limits<double>::infinity(), -0.),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), -0.),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), -0.),
+    std::complex<T>(-2, -0.),
+    std::complex<T>(-1, -0.),
+    std::complex<T>(-0.5, -0.),
+    std::complex<T>(-0., -0.),
+    std::complex<T>(+0., -0.),
+    std::complex<T>(0.5, -0.),
+    std::complex<T>(1, -0.),
+    std::complex<T>(2, -0.),
+    std::complex<T>(std::numeric_limits<T>::infinity(), -0.),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), +0.),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), +0.),
-    std::complex<double>(-2, +0.),
-    std::complex<double>(-1, +0.),
-    std::complex<double>(-0.5, +0.),
-    std::complex<double>(-0., +0.),
-    std::complex<double>(+0., +0.),
-    std::complex<double>(0.5, +0.),
-    std::complex<double>(1, +0.),
-    std::complex<double>(2, +0.),
-    std::complex<double>(std::numeric_limits<double>::infinity(), +0.),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), +0.),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), +0.),
+    std::complex<T>(-2, +0.),
+    std::complex<T>(-1, +0.),
+    std::complex<T>(-0.5, +0.),
+    std::complex<T>(-0., +0.),
+    std::complex<T>(+0., +0.),
+    std::complex<T>(0.5, +0.),
+    std::complex<T>(1, +0.),
+    std::complex<T>(2, +0.),
+    std::complex<T>(std::numeric_limits<T>::infinity(), +0.),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), 0.5),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), 0.5),
-    std::complex<double>(-2, 0.5),
-    std::complex<double>(-1, 0.5),
-    std::complex<double>(-0.5, 0.5),
-    std::complex<double>(-0., 0.5),
-    std::complex<double>(+0., 0.5),
-    std::complex<double>(0.5, 0.5),
-    std::complex<double>(1, 0.5),
-    std::complex<double>(2, 0.5),
-    std::complex<double>(std::numeric_limits<double>::infinity(), 0.5),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), 0.5),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), 0.5),
+    std::complex<T>(-2, 0.5),
+    std::complex<T>(-1, 0.5),
+    std::complex<T>(-0.5, 0.5),
+    std::complex<T>(-0., 0.5),
+    std::complex<T>(+0., 0.5),
+    std::complex<T>(0.5, 0.5),
+    std::complex<T>(1, 0.5),
+    std::complex<T>(2, 0.5),
+    std::complex<T>(std::numeric_limits<T>::infinity(), 0.5),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), 1),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), 1),
-    std::complex<double>(-2, 1),
-    std::complex<double>(-1, 1),
-    std::complex<double>(-0.5, 1),
-    std::complex<double>(-0., 1),
-    std::complex<double>(+0., 1),
-    std::complex<double>(0.5, 1),
-    std::complex<double>(1, 1),
-    std::complex<double>(2, 1),
-    std::complex<double>(std::numeric_limits<double>::infinity(), 1),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), 1),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), 1),
+    std::complex<T>(-2, 1),
+    std::complex<T>(-1, 1),
+    std::complex<T>(-0.5, 1),
+    std::complex<T>(-0., 1),
+    std::complex<T>(+0., 1),
+    std::complex<T>(0.5, 1),
+    std::complex<T>(1, 1),
+    std::complex<T>(2, 1),
+    std::complex<T>(std::numeric_limits<T>::infinity(), 1),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), 2),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), 2),
-    std::complex<double>(-2, 2),
-    std::complex<double>(-1, 2),
-    std::complex<double>(-0.5, 2),
-    std::complex<double>(-0., 2),
-    std::complex<double>(+0., 2),
-    std::complex<double>(0.5, 2),
-    std::complex<double>(1, 2),
-    std::complex<double>(2, 2),
-    std::complex<double>(std::numeric_limits<double>::infinity(), 2),
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), 2),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), 2),
+    std::complex<T>(-2, 2),
+    std::complex<T>(-1, 2),
+    std::complex<T>(-0.5, 2),
+    std::complex<T>(-0., 2),
+    std::complex<T>(+0., 2),
+    std::complex<T>(0.5, 2),
+    std::complex<T>(1, 2),
+    std::complex<T>(2, 2),
+    std::complex<T>(std::numeric_limits<T>::infinity(), 2),
 
-    std::complex<double>(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::infinity()),
-    std::complex<double>(-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()),
-    std::complex<double>(-2, std::numeric_limits<double>::infinity()),
-    std::complex<double>(-1, std::numeric_limits<double>::infinity()),
-    std::complex<double>(-0.5, std::numeric_limits<double>::infinity()),
-    std::complex<double>(-0., std::numeric_limits<double>::infinity()),
-    std::complex<double>(+0., std::numeric_limits<double>::infinity()),
-    std::complex<double>(0.5, std::numeric_limits<double>::infinity()),
-    std::complex<double>(1, std::numeric_limits<double>::infinity()),
-    std::complex<double>(2, std::numeric_limits<double>::infinity()),
-    std::complex<double>(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())
+    std::complex<T>(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::infinity()),
+    std::complex<T>(-std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity()),
+    std::complex<T>(-2, std::numeric_limits<T>::infinity()),
+    std::complex<T>(-1, std::numeric_limits<T>::infinity()),
+    std::complex<T>(-0.5, std::numeric_limits<T>::infinity()),
+    std::complex<T>(-0., std::numeric_limits<T>::infinity()),
+    std::complex<T>(+0., std::numeric_limits<T>::infinity()),
+    std::complex<T>(0.5, std::numeric_limits<T>::infinity()),
+    std::complex<T>(1, std::numeric_limits<T>::infinity()),
+    std::complex<T>(2, std::numeric_limits<T>::infinity()),
+    std::complex<T>(std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity()),
 };
 
 enum {zero, non_zero, inf, NaN, non_zero_nan};
@@ -230,17 +231,15 @@ classify(const std::complex<T>& x)
     return non_zero;
 }
 
-inline
-int
-classify(double x)
-{
-    if (x == 0)
-        return zero;
-    if (std::isinf(x))
-        return inf;
-    if (std::isnan(x))
-        return NaN;
-    return non_zero;
+template <class T>
+inline int classify(T x) {
+  if (x == 0)
+    return zero;
+  if (std::isinf(x))
+    return inf;
+  if (std::isnan(x))
+    return NaN;
+  return non_zero;
 }
 
 void is_about(float x, float y)
diff --git a/libcxx/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp b/libcxx/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp
index d12dfd994b0ae9..cd8c5389c6caa4 100644
--- a/libcxx/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp
+++ b/libcxx/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp
@@ -34,18 +34,18 @@ test()
     return true;
 }
 
-TEST_CONSTEXPR_CXX20
-bool
-test_edges()
-{
-  const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
+template <class T>
+TEST_CONSTEXPR_CXX20 bool test_edges() {
+  const unsigned N = sizeof(testcases<T>) / sizeof(testcases<T>[0]);
   int classification[N];
   for (unsigned i=0; i < N; ++i)
-    classification[i] = classify(testcases[i]);
+    classification[i] = classify(testcases<T>[i]);
 
   for (unsigned i = 0; i < N; ++i) {
+    auto const x = testcases<T>[i];
     for (unsigned j = 0; j < N; ++j) {
-      std::complex<double> r = testcases[i] / testcases[j];
+      auto const y      = testcases<T>[j];
+      std::complex<T> r = x / y;
       switch (classification[i]) {
       case zero:
         switch (classification[j]) {
@@ -153,13 +153,17 @@ int main(int, char**)
     test<float>();
     test<double>();
     test<long double>();
-    test_edges();
+    test_edges<float>();
+    test_edges<double>();
+    test_edges<long double>();
 
 #if TEST_STD_VER > 17
     static_assert(test<float>());
     static_assert(test<double>());
     static_assert(test<long double>());
-    static_assert(test_edges());
+    static_assert(test_edges<float>());
+    static_assert(test_edges<double>());
+    static_assert(test_edges<long double>());
 #endif
 
     return 0;
diff --git a/libcxx/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp b/libcxx/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp
index 817d6cdf492d30..2f8af2c313e8eb 100644
--- a/libcxx/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp
+++ b/libcxx/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp
@@ -33,87 +33,80 @@ test()
 
 // test edges
 
-TEST_CONSTEXPR_CXX20 bool test_edges()
-{
-    const unsigned N = sizeof(testcases) / sizeof(testcases[0]);
-    int classification[N];
-    for (unsigned i=0; i < N; ++i)
-        classification[i] = classify(testcases[i]);
+template <class T>
+TEST_CONSTEXPR_CXX20 bool test_edges() {
+  const unsigned N = sizeof(testcases<T>) / sizeof(testcases<T>[0]);
+  int classification[N];
+  for (unsigned i = 0; i < N; ++i)
+    classification[i] = classify(testcases<T>[i]);
 
-    for (unsigned i = 0; i < N; ++i)
-    {
-        for (unsigned j = 0; j < N; ++j)
-        {
-            std::complex<double> r = testcases[i] * testcases[j];
-            switch (classification[i])
-            {
-            case zero:
-                switch (classification[j])
-                {
-                case zero:
-                case non_zero:
-                    assert(classify(r) == zero);
-                    break;
-                case inf:
-                case NaN:
-                case non_zero_nan:
-                    assert(classify(r) == NaN);
-                    break;
-                }
-                break;
-            case non_zero:
-                switch (classification[j])
-                {
-                case zero:
-                    assert(classify(r) == zero);
-                    break;
-                case non_zero:
-                    assert(classify(r) == non_zero);
-                    break;
-                case inf:
-                    assert(classify(r) == inf);
-                    break;
-                case NaN:
-                case non_zero_nan:
-                    assert(classify(r) == NaN);
-                    break;
-                }
-                break;
-            case inf:
-                switch (classification[j])
-                {
-                case zero:
-                case NaN:
-                    assert(classify(r) == NaN);
-                    break;
-                case non_zero:
-                case inf:
-                case non...
[truncated]

@github-actions
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff a8d2aeec8732c8d158f5b194a5191c0805bcd961 329ce37243c52547fb00243ac7bc59139d3f5125 --extensions h,cpp -- libcxx/test/std/numerics/complex.number/cases.h libcxx/test/std/numerics/complex.number/complex.ops/complex_divide_complex.pass.cpp libcxx/test/std/numerics/complex.number/complex.ops/complex_times_complex.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/acos.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/acosh.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/asin.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/asinh.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/atan.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/atanh.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/cos.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/cosh.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/exp.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/log.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/log10.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/pow_complex_complex.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/pow_complex_scalar.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/pow_scalar_complex.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/sin.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/sinh.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/tan.pass.cpp libcxx/test/std/numerics/complex.number/complex.transcendentals/tanh.pass.cpp libcxx/test/std/numerics/complex.number/complex.value.ops/abs.pass.cpp libcxx/test/std/numerics/complex.number/complex.value.ops/arg.pass.cpp libcxx/test/std/numerics/complex.number/complex.value.ops/norm.pass.cpp libcxx/test/std/numerics/complex.number/complex.value.ops/polar.pass.cpp libcxx/test/std/numerics/complex.number/complex.value.ops/proj.pass.cpp
View the diff from clang-format here.
diff --git a/libcxx/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp b/libcxx/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp
index 43813ba6fd..18344d4070 100644
--- a/libcxx/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp
+++ b/libcxx/test/std/numerics/complex.number/complex.transcendentals/sqrt.pass.cpp
@@ -35,21 +35,19 @@ test()
     test(std::complex<T>(64, 0), std::complex<T>(8, 0));
 }
 
-template<class T>
-bool in_range(const T value, const T low, const T high) { return low < value && value < high; }
+template <class T>
+bool in_range(const T value, const T low, const T high) {
+  return low < value && value < high;
+}
 
 // cosine calculations for std::arg terminate at different times based on the precision of T,
 // and can produce a very small negative number instead of a very small positive one, so we
 // should actually check that we're really close to zero instead of positive.
-bool approaching_zero(const float value) {
-    return value == -0.0f || in_range(value, -4.38e-5f, 4.38e-5f);
-}
+bool approaching_zero(const float value) { return value == -0.0f || in_range(value, -4.38e-5f, 4.38e-5f); }
 
 bool approaching_zero(double) { return false; }
 
-bool approaching_zero(const long double value) {
-    return value == -0.0f || in_range(value, -3.0e-17L, 3.0e-17L);
-}
+bool approaching_zero(const long double value) { return value == -0.0f || in_range(value, -3.0e-17L, 3.0e-17L); }
 
 template <class T>
 void test_edges() {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants