Skip to content

STY: clang-format repo #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
BasedOnStyle: LLVM
Standard: Cpp11
Standard: c++17
UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Attach
Cpp11BracedListStyle: true
NamespaceIndentation: Inner
AlwaysBreakTemplateDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterCStyleCast: false
ColumnLimit: 120
InsertNewlineAtEOF: true
AlignAfterOpenBracket: BlockIndent
IncludeBlocks: Preserve
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# clang-format repo gh-5
e6323cae55daee686221c54160994ee1c7825ba5
2 changes: 1 addition & 1 deletion include/xsf/airy.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ inline void airyb(double x, double *ai, double *bi, double *ad, double *bd) {
*ad = c1 * df - c2 * dg;
*bd = sr3 * (c1 * df + c2 * dg);
} else {
km = (int) (24.5 - xa);
km = (int)(24.5 - xa);
if (xa < 6.0)
km = 14;
if (xa > 15.0)
Expand Down
11,961 changes: 6,155 additions & 5,806 deletions include/xsf/amos/amos.h

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions include/xsf/binom.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ XSF_HOST_DEVICE inline double binom(double n, double k) {
return 1 / (n + 1) / cephes::beta(1 + n - k, 1 + k);
}

XSF_HOST_DEVICE inline float binom(float n, float k) {
return binom(static_cast<double>(n), static_cast<double>(k));
}
XSF_HOST_DEVICE inline float binom(float n, float k) { return binom(static_cast<double>(n), static_cast<double>(k)); }

} // namespace xsf
18 changes: 8 additions & 10 deletions include/xsf/cdflib.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ XSF_HOST_DEVICE inline double gdtrib(double a, double p, double x) {
}
double q = 1.0 - p;
auto func = [a, p, q, x](double b) {
if (p <= q) {
return cephes::igam(b, a * x) - p;
}
return q - cephes::igamc(b, a * x);
if (p <= q) {
return cephes::igam(b, a * x) - p;
}
return q - cephes::igamc(b, a * x);
};
double lower_bound = std::numeric_limits<double>::min();
double upper_bound = std::numeric_limits<double>::max();
Expand All @@ -71,9 +71,8 @@ XSF_HOST_DEVICE inline double gdtrib(double a, double p, double x) {
* number of iterations needed in this bracket search to check all normalized
* floating point values.
*/
auto [xl, xr, f_xl, f_xr, bracket_status] = detail::bracket_root_for_cdf_inversion(
func, 1.0, lower_bound, upper_bound, -0.875, 7.0, 0.125, 8, false, 342
);
auto [xl, xr, f_xl, f_xr, bracket_status] =
detail::bracket_root_for_cdf_inversion(func, 1.0, lower_bound, upper_bound, -0.875, 7.0, 0.125, 8, false, 342);
if (bracket_status == 1) {
set_error("gdtrib", SF_ERROR_UNDERFLOW, NULL);
return 0.0;
Expand All @@ -86,9 +85,8 @@ XSF_HOST_DEVICE inline double gdtrib(double a, double p, double x) {
set_error("gdtrib", SF_ERROR_OTHER, "Computational Error");
return std::numeric_limits<double>::quiet_NaN();
}
auto [result, root_status] = detail::find_root_chandrupatla(
func, xl, xr, f_xl, f_xr, std::numeric_limits<double>::epsilon(), 1e-100, 100
);
auto [result, root_status] =
detail::find_root_chandrupatla(func, xl, xr, f_xl, f_xr, std::numeric_limits<double>::epsilon(), 1e-100, 100);
if (root_status) {
/* The root finding return should only fail if there's a bug in our code. */
set_error("gdtrib", SF_ERROR_OTHER, "Computational Error, (%.17g, %.17g, %.17g)", a, p, x);
Expand Down
6 changes: 3 additions & 3 deletions include/xsf/cephes/beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ namespace cephes {
b = Gamma(b);
if (std::isinf(y)) {
goto overflow;
}
}

if (std::abs(std::abs(a*y) - 1.0) > std::abs(std::abs(b*y) - 1.0)) {
if (std::abs(std::abs(a * y) - 1.0) > std::abs(std::abs(b * y) - 1.0)) {
y = b * y;
y *= a;
} else {
Expand Down Expand Up @@ -239,7 +239,7 @@ namespace cephes {
return (sign * std::numeric_limits<double>::infinity());
}

if (std::abs(std::abs(a*y) - 1.0) > std::abs(std::abs(b*y) - 1.0)) {
if (std::abs(std::abs(a * y) - 1.0) > std::abs(std::abs(b * y) - 1.0)) {
y = b * y;
y *= a;
} else {
Expand Down
133 changes: 66 additions & 67 deletions include/xsf/cephes/cbrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,75 +57,74 @@ namespace cephes {
inline constexpr double CBRT2I = 0.79370052598409973737585;
inline constexpr double CBRT4I = 0.62996052494743658238361;

}
} // namespace detail

XSF_HOST_DEVICE inline double cbrt(double x) {
int e, rem, sign;
double z;

if (!std::isfinite(x)) {
return x;
}
if (x == 0) {
return (x);
}
if (x > 0) {
sign = 1;
} else {
sign = -1;
x = -x;
}

z = x;
/* extract power of 2, leaving
* mantissa between 0.5 and 1
*/
x = std::frexp(x, &e);

/* Approximate cube root of number between .5 and 1,
* peak relative error = 9.2e-6
*/
x = (((-1.3466110473359520655053e-1 * x + 5.4664601366395524503440e-1) * x - 9.5438224771509446525043e-1) *
x +
1.1399983354717293273738e0) *
x +
4.0238979564544752126924e-1;

/* exponent divided by 3 */
if (e >= 0) {
rem = e;
e /= 3;
rem -= 3 * e;
if (rem == 1) {
x *= detail::CBRT2;
} else if (rem == 2) {
x *= detail::CBRT4;
}
}
/* argument less than 1 */
else {
e = -e;
rem = e;
e /= 3;
rem -= 3 * e;
if (rem == 1) {
x *= detail::CBRT2I;
} else if (rem == 2) {
x *= detail::CBRT4I;
}
e = -e;
}

/* multiply by power of 2 */
x = std::ldexp(x, e);

/* Newton iteration */
x -= (x - (z / (x * x))) * 0.33333333333333333333;
x -= (x - (z / (x * x))) * 0.33333333333333333333;

if (sign < 0)
x = -x;
return (x);
int e, rem, sign;
double z;

if (!std::isfinite(x)) {
return x;
}
if (x == 0) {
return (x);
}
if (x > 0) {
sign = 1;
} else {
sign = -1;
x = -x;
}

z = x;
/* extract power of 2, leaving
* mantissa between 0.5 and 1
*/
x = std::frexp(x, &e);

/* Approximate cube root of number between .5 and 1,
* peak relative error = 9.2e-6
*/
x = (((-1.3466110473359520655053e-1 * x + 5.4664601366395524503440e-1) * x - 9.5438224771509446525043e-1) * x +
1.1399983354717293273738e0) *
x +
4.0238979564544752126924e-1;

/* exponent divided by 3 */
if (e >= 0) {
rem = e;
e /= 3;
rem -= 3 * e;
if (rem == 1) {
x *= detail::CBRT2;
} else if (rem == 2) {
x *= detail::CBRT4;
}
}
/* argument less than 1 */
else {
e = -e;
rem = e;
e /= 3;
rem -= 3 * e;
if (rem == 1) {
x *= detail::CBRT2I;
} else if (rem == 2) {
x *= detail::CBRT4I;
}
e = -e;
}

/* multiply by power of 2 */
x = std::ldexp(x, e);

/* Newton iteration */
x -= (x - (z / (x * x))) * 0.33333333333333333333;
x -= (x - (z / (x * x))) * 0.33333333333333333333;

if (sign < 0)
x = -x;
return (x);
}

} // namespace cephes
Expand Down
2 changes: 1 addition & 1 deletion include/xsf/cephes/chdtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace cephes {
if (x < 0.0) {
set_error("chdtr", SF_ERROR_DOMAIN, NULL);
return (std::numeric_limits<double>::quiet_NaN());
}
}
return (igamc(df / 2.0, x / 2.0));
}

Expand Down
44 changes: 22 additions & 22 deletions include/xsf/cephes/dd_real.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ namespace cephes {

// Arithmetic operations

XSF_HOST_DEVICE inline double_double operator-(const double_double &x) {
return double_double(-x.hi, -x.lo);
}
XSF_HOST_DEVICE inline double_double operator-(const double_double &x) { return double_double(-x.hi, -x.lo); }

XSF_HOST_DEVICE inline double_double operator+(const double_double &lhs, const double_double &rhs) {
/* This one satisfies IEEE style error bound,
Expand Down Expand Up @@ -382,15 +380,15 @@ namespace cephes {
return lhs - rhs * n;
}

XSF_HOST_DEVICE inline std::pair<double_double, double_double> divrem(const double_double &lhs,
const double_double &rhs) {
XSF_HOST_DEVICE inline std::pair<double_double, double_double>
divrem(const double_double &lhs, const double_double &rhs) {
double_double n = round(lhs / rhs);
double_double remainder = lhs - n * rhs;
return {n, remainder};
}

XSF_HOST_DEVICE inline double_double fma(
const double_double &a, const double_double &b, const double_double &c) {
XSF_HOST_DEVICE inline double_double
fma(const double_double &a, const double_double &b, const double_double &c) {
// TODO: make an accurate fma
return a * b + c;
}
Expand Down Expand Up @@ -442,21 +440,23 @@ namespace cephes {
return double_double(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity());
}

const double_double inv_fact[] = {double_double(1.66666666666666657e-01, 9.25185853854297066e-18),
double_double(4.16666666666666644e-02, 2.31296463463574266e-18),
double_double(8.33333333333333322e-03, 1.15648231731787138e-19),
double_double(1.38888888888888894e-03, -5.30054395437357706e-20),
double_double(1.98412698412698413e-04, 1.72095582934207053e-22),
double_double(2.48015873015873016e-05, 2.15119478667758816e-23),
double_double(2.75573192239858925e-06, -1.85839327404647208e-22),
double_double(2.75573192239858883e-07, 2.37677146222502973e-23),
double_double(2.50521083854417202e-08, -1.44881407093591197e-24),
double_double(2.08767569878681002e-09, -1.20734505911325997e-25),
double_double(1.60590438368216133e-10, 1.25852945887520981e-26),
double_double(1.14707455977297245e-11, 2.06555127528307454e-28),
double_double(7.64716373181981641e-13, 7.03872877733453001e-30),
double_double(4.77947733238738525e-14, 4.39920548583408126e-31),
double_double(2.81145725434552060e-15, 1.65088427308614326e-31)};
const double_double inv_fact[] = {
double_double(1.66666666666666657e-01, 9.25185853854297066e-18),
double_double(4.16666666666666644e-02, 2.31296463463574266e-18),
double_double(8.33333333333333322e-03, 1.15648231731787138e-19),
double_double(1.38888888888888894e-03, -5.30054395437357706e-20),
double_double(1.98412698412698413e-04, 1.72095582934207053e-22),
double_double(2.48015873015873016e-05, 2.15119478667758816e-23),
double_double(2.75573192239858925e-06, -1.85839327404647208e-22),
double_double(2.75573192239858883e-07, 2.37677146222502973e-23),
double_double(2.50521083854417202e-08, -1.44881407093591197e-24),
double_double(2.08767569878681002e-09, -1.20734505911325997e-25),
double_double(1.60590438368216133e-10, 1.25852945887520981e-26),
double_double(1.14707455977297245e-11, 2.06555127528307454e-28),
double_double(7.64716373181981641e-13, 7.03872877733453001e-30),
double_double(4.77947733238738525e-14, 4.39920548583408126e-31),
double_double(2.81145725434552060e-15, 1.65088427308614326e-31)
};

// Math constants
const double_double E = double_double(2.718281828459045091e+00, 1.445646891729250158e-16);
Expand Down
2 changes: 1 addition & 1 deletion include/xsf/cephes/ellik.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace cephes {
return (phi);
a = 1.0 - m;
if (a == 0.0) {
if (std::abs(phi) >= (double) M_PI_2) {
if (std::abs(phi) >= (double)M_PI_2) {
set_error("ellik", SF_ERROR_SINGULAR, NULL);
return (std::numeric_limits<double>::infinity());
}
Expand Down
12 changes: 7 additions & 5 deletions include/xsf/cephes/expn.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
#include "../config.h"
#include "../error.h"
#include "const.h"
#include "rgamma.h"
#include "polevl.h"
#include "rgamma.h"

namespace xsf {
namespace cephes {
Expand All @@ -78,10 +78,12 @@ namespace cephes {
constexpr double expn_A1[] = {1.00000000000000000};
constexpr double expn_A2[] = {-2.00000000000000000, 1.00000000000000000};
constexpr double expn_A3[] = {6.00000000000000000, -8.00000000000000000, 1.00000000000000000};
constexpr double expn_A4[] = {-24.0000000000000000, 58.0000000000000000, -22.0000000000000000,
1.00000000000000000};
constexpr double expn_A5[] = {120.000000000000000, -444.000000000000000, 328.000000000000000,
-52.0000000000000000, 1.00000000000000000};
constexpr double expn_A4[] = {
-24.0000000000000000, 58.0000000000000000, -22.0000000000000000, 1.00000000000000000
};
constexpr double expn_A5[] = {
120.000000000000000, -444.000000000000000, 328.000000000000000, -52.0000000000000000, 1.00000000000000000
};
constexpr double expn_A6[] = {-720.000000000000000, 3708.00000000000000, -4400.00000000000000,
1452.00000000000000, -114.000000000000000, 1.00000000000000000};
constexpr double expn_A7[] = {5040.00000000000000, -33984.0000000000000, 58140.0000000000000,
Expand Down
Loading
Loading