Skip to content

Commit

Permalink
Merge pull request #37 from NREL/SAM_1223
Browse files Browse the repository at this point in the history
Update fabs to std::abs per SAM #1223
  • Loading branch information
sjanzou authored Nov 10, 2022
2 parents ba6fce1 + 47edc2c commit 48d2c53
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/stdlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#include <future>
#include <chrono>

#include <cmath>
#include <float.h>
#include <string.h>

#include <lk/stdlib.h>
Expand Down Expand Up @@ -2213,7 +2211,7 @@ static void _mpi(lk::invoke_t &cxt) {

static void _mabs(lk::invoke_t &cxt) {
LK_DOC("abs", "Returns the absolute value of a number.", "(real:x):real");
cxt.result().assign(::fabs(cxt.arg(0).as_number()));
cxt.result().assign(std::abs(cxt.arg(0).as_number()));
}

static void _msgn(lk::invoke_t &cxt) {
Expand Down Expand Up @@ -3704,7 +3702,7 @@ double lk::besj0(double x) {
double ax, z;
double xx, y, ans, ans1, ans2;

if ((ax = fabs(x)) < 8.0) {
if ((ax = std::abs(x)) < 8.0) {
y = x * x;
ans1 = 57568490574.0 + y * (-13362590354.0 + y * (651619640.7
+
Expand All @@ -3730,7 +3728,7 @@ double lk::besj1(double x) {
double ax, z;
double xx, y, ans, ans1, ans2;

if ((ax = fabs(x)) < 8.0) {
if ((ax = std::abs(x)) < 8.0) {
y = x * x;
ans1 = x * (72362614232.0 + y * (-7895059235.0 + y * (242396853.1
+ y * (-2972611.439 +
Expand Down Expand Up @@ -3813,7 +3811,7 @@ double lk::besi0(double x) {
double ax, ans;
double y;

if ((ax = fabs(x)) < 3.75) {
if ((ax = std::abs(x)) < 3.75) {
y = x / 3.75;
y *= y;
ans = 1.0 + y * (3.5156229 + y * (3.0899424 + y * (1.2067492
Expand Down Expand Up @@ -3863,7 +3861,7 @@ double lk::besi1(double x) {
double ax, ans;
double y;

if ((ax = fabs(x)) < 3.75) {
if ((ax = std::abs(x)) < 3.75) {
y = x / 3.75;
y *= y;
ans = ax * (0.5 + y * (0.87890594 + y * (0.51498869 + y * (0.15084934
Expand Down Expand Up @@ -3933,27 +3931,27 @@ double lk::betacf(double a, double b, double x) {
qam = a - 1.0;
c = 1.0;
d = 1.0 - qab * x / qap;
if (fabs(d) < FPMIN) d = FPMIN;
if (std::abs(d) < FPMIN) d = FPMIN;
d = 1.0 / d;
h = d;
for (m = 1; m <= MAXIT; m++) {
m2 = 2 * m;
aa = m * (b - m) * x / ((qam + m2) * (a + m2));
d = 1.0 + aa * d;
if (fabs(d) < FPMIN) d = FPMIN;
if (std::abs(d) < FPMIN) d = FPMIN;
c = 1.0 + aa / c;
if (fabs(c) < FPMIN) c = FPMIN;
if (std::abs(c) < FPMIN) c = FPMIN;
d = 1.0 / d;
h *= d * c;
aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2));
d = 1.0 + aa * d;
if (fabs(d) < FPMIN) d = FPMIN;
if (std::abs(d) < FPMIN) d = FPMIN;
c = 1.0 + aa / c;
if (fabs(c) < FPMIN) c = FPMIN;
if (std::abs(c) < FPMIN) c = FPMIN;
d = 1.0 / d;
del = d * c;
h *= del;
if (fabs(del - 1.0) < EPS) break;
if (std::abs(del - 1.0) < EPS) break;
}

if (m > MAXIT) throw lk::error_t("a or b too big, or MAXIT too small in betacf");
Expand Down Expand Up @@ -4021,7 +4019,7 @@ void lk::gser(double *gamser, double a, double x, double *gln) {
++ap;
del *= x / ap;
sum += del;
if (fabs(del) < fabs(sum) * EPS) {
if (std::abs(del) < std::abs(sum) * EPS) {
*gamser = sum * exp(-x + a * log(x) - (*gln));
return;
}
Expand Down Expand Up @@ -4051,13 +4049,13 @@ void lk::gcf(double *gammcf, double a, double x, double *gln) {
an = -i * (i - a);
b += 2.0;
d = an * d + b;
if (fabs(d) < FPMIN) d = FPMIN;
if (std::abs(d) < FPMIN) d = FPMIN;
c = b + an / c;
if (fabs(c) < FPMIN) c = FPMIN;
if (std::abs(c) < FPMIN) c = FPMIN;
d = 1.0 / d;
del = d * c;
h *= del;
if (fabs(del - 1.0) < EPS) break;
if (std::abs(del - 1.0) < EPS) break;
}
if (i > ITMAX) throw lk::error_t("a too large, ITMAX too small in gcf");
*gammcf = exp(-x + a * log(x) - (*gln)) * h;
Expand Down

0 comments on commit 48d2c53

Please sign in to comment.