Skip to content
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

Update fabs to std::abs per SAM #1223 #37

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Changes from 1 commit
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
33 changes: 16 additions & 17 deletions src/stdlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
#include <future>
#include <chrono>

#include <cmath>
#include <float.h>
//#include <float.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented out code

#include <string.h>

#include <lk/stdlib.h>
Expand Down Expand Up @@ -2213,7 +2212,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 +3703,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 +3729,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 +3812,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 +3862,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 +3932,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 +4020,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 +4050,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