Skip to content

feat: add C implementation for @stdlib/math/base/special/erfcx #2040

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 24 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
aee180e
feat(math): c implementation of `@stdlib/math/base/special/erfcx
USERSATOSHI Mar 21, 2024
0eb6f10
style: updated readme.md for @stdlib/math/base/special/erfcx
USERSATOSHI Mar 25, 2024
b714b73
fix: added missing semicolon and fixed dependecies in manifest.json
USERSATOSHI Mar 25, 2024
b39d36e
style: converted missed @returns to @return
USERSATOSHI Mar 25, 2024
6ab0b8e
style: removed @private
USERSATOSHI Mar 25, 2024
4fda9a4
Apply suggestions from code review
kgryte Mar 25, 2024
2b40a3b
Apply suggestions from code review
kgryte Mar 25, 2024
dc27930
Apply suggestions from code review
kgryte Mar 25, 2024
bd9b4e5
Apply suggestions from code review
kgryte Mar 25, 2024
210228c
Apply suggestions from code review
kgryte Mar 25, 2024
2f2b3b1
style: fixed main.c style, updating copyrights in benchmark and added…
USERSATOSHI Mar 25, 2024
1b9d45b
style: applied style changes according to review
USERSATOSHI Mar 26, 2024
00e5f99
Merge branch 'stdlib-js:develop' into erfcx
USERSATOSHI Apr 10, 2024
18a5d4e
Update lib/node_modules/@stdlib/math/base/special/erfcx/benchmark/c/n…
gunjjoshi Aug 23, 2024
98b4052
Update lib/node_modules/@stdlib/math/base/special/erfcx/benchmark/c/n…
gunjjoshi Aug 23, 2024
dc8da04
chore: update benchmarks
gunjjoshi Aug 23, 2024
d74088a
Update lib/node_modules/@stdlib/math/base/special/erfcx/benchmark/ben…
gunjjoshi Aug 23, 2024
a817c42
style: style changes, use isnan in main.js, correct function name
gunjjoshi Aug 23, 2024
4d9ba5d
docs: update tests
gunjjoshi Aug 23, 2024
b1bf893
bench: use correct function name
gunjjoshi Aug 23, 2024
efa7e5d
docs: include function signature in README.md
gunjjoshi Aug 23, 2024
2e00169
docs: remove unused stdint include
gunjjoshi Aug 23, 2024
e3a2854
test: decrease tolerances
gunjjoshi Aug 23, 2024
3d53747
docs: fix function name in example code
Planeshifter Sep 2, 2024
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
Prev Previous commit
Next Next commit
style: updated readme.md for @stdlib/math/base/special/erfcx
  • Loading branch information
USERSATOSHI committed Mar 25, 2024
commit 0eb6f10816e04f20b13a9fd09e37ce20d9fa8a84
24 changes: 12 additions & 12 deletions lib/node_modules/@stdlib/math/base/special/erfcx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ for ( i = 0; i < x.length; i++ ) {
Evaluates the [scaled complementary error function][complementary-error-function].

```c
double y = stdlib_base_erfcx( 0.0 );
* // returns 1.0
double y = stdlib_base_erfcx( 0.0 );
// returns 1.0

* double y = stdlib_base_erfcx( 1.0 );
* // returns ~0.4276
double y = stdlib_base_erfcx( 1.0 );
// returns ~0.4276
```

</section>
Expand All @@ -181,14 +181,14 @@ Evaluates the [scaled complementary error function][complementary-error-function
#include <stdio.h>

int main( void ) {
const double x[] = { 0.0, 0.22, 0.44, 0.67, 0.89, 1.11, 1.33, 1.56, 1.78, 2.0 };

double v;
int i;
for ( i = 0; i < 10; i++ ) {
v = stdlib_base_erfcx( x[ i ] );
printf( "x: %lf, erfcx(x): %lf\n", x[ i ], v );
}
const double x[] = { 0.0, 0.22, 0.44, 0.67, 0.89, 1.11, 1.33, 1.56, 1.78, 2.0 };

double v;
int i;
for ( i = 0; i < 10; i++ ) {
v = stdlib_base_erfcx( x[ i ] );
printf( "x: %lf, erfcx(x): %lf\n", x[ i ], v );
}
}
```

Expand Down
88 changes: 44 additions & 44 deletions lib/node_modules/@stdlib/math/base/special/erfcx/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* @return result
*/
double p0(double t) {
return 0.70878032454106438663e-3 + (0.71234091047026302958e-3 + (0.35779077297597742384e-5 + (0.17403143962587937815e-7 + (0.81710660047307788845e-10 + (0.36885022360434957634e-12 + 0.15917038551111111111e-14 * t) * t) * t) * t) * t) * t;
return 0.70878032454106438663e-3 + (0.71234091047026302958e-3 + (0.35779077297597742384e-5 + (0.17403143962587937815e-7 + (0.81710660047307788845e-10 + (0.36885022360434957634e-12 + 0.15917038551111111111e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -67,7 +67,7 @@ double p0(double t) {
* @return result
*/
double p1(double t) {
return 0.21479143208285144230e-2 + (0.72686402367379996033e-3 + (0.36843175430938995552e-5 + (0.18071841272149201685e-7 + (0.85496449296040325555e-10 + (0.38852037518534291510e-12 + 0.16868473576888888889e-14 * t) * t) * t) * t) * t) * t;
return 0.21479143208285144230e-2 + (0.72686402367379996033e-3 + (0.36843175430938995552e-5 + (0.18071841272149201685e-7 + (0.85496449296040325555e-10 + (0.38852037518534291510e-12 + 0.16868473576888888889e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -77,7 +77,7 @@ double p1(double t) {
* @return result
*/
double p2(double t) {
return 0.36165255935630175090e-2 + (0.74182092323555510862e-3 + (0.37948319957528242260e-5 + (0.18771627021793087350e-7 + (0.89484715122415089123e-10 + (0.40935858517772440862e-12 + 0.17872061464888888889e-14 * t) * t) * t) * t) * t) * t;
return 0.36165255935630175090e-2 + (0.74182092323555510862e-3 + (0.37948319957528242260e-5 + (0.18771627021793087350e-7 + (0.89484715122415089123e-10 + (0.40935858517772440862e-12 + 0.17872061464888888889e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -87,7 +87,7 @@ double p2(double t) {
* @return result
*/
double p3(double t) {
return 0.51154983860031979264e-2 + (0.75722840734791660540e-3 + (0.39096425726735703941e-5 + (0.19504168704300468210e-7 + (0.93687503063178993915e-10 + (0.43143925959079664747e-12 + 0.18939926435555555556e-14 * t) * t) * t) * t) * t) * t;
return 0.51154983860031979264e-2 + (0.75722840734791660540e-3 + (0.39096425726735703941e-5 + (0.19504168704300468210e-7 + (0.93687503063178993915e-10 + (0.43143925959079664747e-12 + 0.18939926435555555556e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -97,7 +97,7 @@ double p3(double t) {
* @return result
*/
double p4(double t) {
return 0.66457513172673049824e-2 + (0.77310406054447454920e-3 + (0.40289510589399439385e-5 + (0.20271233238288381092e-7 + (0.98117631321709100264e-10 + (0.45484207406017752971e-12 + 0.20076352213333333333e-14 * t) * t) * t) * t) * t) * t;
return 0.66457513172673049824e-2 + (0.77310406054447454920e-3 + (0.40289510589399439385e-5 + (0.20271233238288381092e-7 + (0.98117631321709100264e-10 + (0.45484207406017752971e-12 + 0.20076352213333333333e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -107,7 +107,7 @@ double p4(double t) {
* @return result
*/
double p5(double t) {
return 0.82082389970241207883e-2 + (0.78946629611881710721e-3 + (0.41529701552622656574e-5 + (0.21074693344544655714e-7 + (0.10278874108587317989e-9 + (0.47965201390613339638e-12 + 0.21285907413333333333e-14 * t) * t) * t) * t) * t) * t;
return 0.82082389970241207883e-2 + (0.78946629611881710721e-3 + (0.41529701552622656574e-5 + (0.21074693344544655714e-7 + (0.10278874108587317989e-9 + (0.47965201390613339638e-12 + 0.21285907413333333333e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -117,7 +117,7 @@ double p5(double t) {
* @return result
*/
double p6(double t) {
return 0.98039537275352193165e-2 + (0.80633440108342840956e-3 + (0.42819241329736982942e-5 + (0.21916534346907168612e-7 + (0.10771535136565470914e-9 + (0.50595972623692822410e-12 + 0.22573462684444444444e-14 * t) * t) * t) * t) * t) * t;
return 0.98039537275352193165e-2 + (0.80633440108342840956e-3 + (0.42819241329736982942e-5 + (0.21916534346907168612e-7 + (0.10771535136565470914e-9 + (0.50595972623692822410e-12 + 0.22573462684444444444e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -127,7 +127,7 @@ double p6(double t) {
* @return result
*/
double p7(double t) {
return 0.11433927298290302370e-1 + (0.82372858383196561209e-3 + (0.44160495311765438816e-5 + (0.22798861426211986056e-7 + (0.11291291745879239736e-9 + (0.53386189365816880454e-12 + 0.23944209546666666667e-14 * t) * t) * t) * t) * t) * t;
return 0.11433927298290302370e-1 + (0.82372858383196561209e-3 + (0.44160495311765438816e-5 + (0.22798861426211986056e-7 + (0.11291291745879239736e-9 + (0.53386189365816880454e-12 + 0.23944209546666666667e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -137,7 +137,7 @@ double p7(double t) {
* @return result
*/
double p8(double t) {
return 0.13099232878814653979e-1 + (0.84167002467906968214e-3 + (0.45555958988457506002e-5 + (0.23723907357214175198e-7 + (0.11839789326602695603e-9 + (0.56346163067550237877e-12 + 0.25403679644444444444e-14 * t) * t) * t) * t) * t) * t;
return 0.13099232878814653979e-1 + (0.84167002467906968214e-3 + (0.45555958988457506002e-5 + (0.23723907357214175198e-7 + (0.11839789326602695603e-9 + (0.56346163067550237877e-12 + 0.25403679644444444444e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -147,7 +147,7 @@ double p8(double t) {
* @return result
*/
double p9(double t) {
return 0.14800987015587535621e-1 + (0.86018092946345943214e-3 + (0.47008265848816866105e-5 + (0.24694040760197315333e-7 + (0.12418779768752299093e-9 + (0.59486890370320261949e-12 + 0.26957764568888888889e-14 * t) * t) * t) * t) * t) * t;
return 0.14800987015587535621e-1 + (0.86018092946345943214e-3 + (0.47008265848816866105e-5 + (0.24694040760197315333e-7 + (0.12418779768752299093e-9 + (0.59486890370320261949e-12 + 0.26957764568888888889e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -157,7 +157,7 @@ double p9(double t) {
* @return result
*/
double p10(double t) {
return 0.16540351739394069380e-1 + (0.87928458641241463952e-3 + (0.48520195793001753903e-5 + (0.25711774900881709176e-7 + (0.13030128534230822419e-9 + (0.62820097586874779402e-12 + 0.28612737351111111111e-14 * t) * t) * t) * t) * t) * t;
return 0.16540351739394069380e-1 + (0.87928458641241463952e-3 + (0.48520195793001753903e-5 + (0.25711774900881709176e-7 + (0.13030128534230822419e-9 + (0.62820097586874779402e-12 + 0.28612737351111111111e-14 * t) * t) * t) * t) * t) * t;
}

/***
Expand All @@ -167,7 +167,7 @@ double p10(double t) {
* @return result
*/
double p11(double t) {
return 0.18318536789842392647e-1 + (0.89900542647891721692e-3 + (0.50094684089553365810e-5 + (0.26779777074218070482e-7 + (0.13675822186304615566e-9 + (0.66358287745352705725e-12 + 0.30375273884444444444e-14 * t) * t) * t) * t) * t) * t;
return 0.18318536789842392647e-1 + (0.89900542647891721692e-3 + (0.50094684089553365810e-5 + (0.26779777074218070482e-7 + (0.13675822186304615566e-9 + (0.66358287745352705725e-12 + 0.30375273884444444444e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -177,7 +177,7 @@ double p11(double t) {
* @return result
*/
double p12(double t) {
return 0.20136801964214276775e-1 + (0.91936908737673676012e-3 + (0.51734830914104276820e-5 + (0.27900878609710432673e-7 + (0.14357976402809042257e-9 + (0.70114790311043728387e-12 + 0.32252476000000000000e-14 * t) * t) * t) * t) * t) * t;
return 0.20136801964214276775e-1 + (0.91936908737673676012e-3 + (0.51734830914104276820e-5 + (0.27900878609710432673e-7 + (0.14357976402809042257e-9 + (0.70114790311043728387e-12 + 0.32252476000000000000e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -187,7 +187,7 @@ double p12(double t) {
* @return result
*/
double p13(double t) {
return 0.21996459598282740954e-1 + (0.94040248155366777784e-3 + (0.53443911508041164739e-5 + (0.29078085538049374673e-7 + (0.15078844500329731137e-9 + (0.74103813647499204269e-12 + 0.34251892320000000000e-14 * t) * t) * t) * t) * t) * t;
return 0.21996459598282740954e-1 + (0.94040248155366777784e-3 + (0.53443911508041164739e-5 + (0.29078085538049374673e-7 + (0.15078844500329731137e-9 + (0.74103813647499204269e-12 + 0.34251892320000000000e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -197,7 +197,7 @@ double p13(double t) {
* @return result
*/
double p14(double t) {
return 0.23898877187226319502e-1 + (0.96213386835900177540e-3 + (0.55225386998049012752e-5 + (0.30314589961047687059e-7 + (0.15840826497296335264e-9 + (0.78340500472414454395e-12 + 0.36381553564444444445e-14 * t) * t) * t) * t) * t) * t;
return 0.23898877187226319502e-1 + (0.96213386835900177540e-3 + (0.55225386998049012752e-5 + (0.30314589961047687059e-7 + (0.15840826497296335264e-9 + (0.78340500472414454395e-12 + 0.36381553564444444445e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -207,7 +207,7 @@ double p14(double t) {
* @return result
*/
double p15(double t) {
return 0.25845480155298518485e-1 + (0.98459293067820123389e-3 + (0.57082915920051843672e-5 + (0.31613782169164830118e-7 + (0.16646478745529630813e-9 + (0.82840985928785407942e-12 + 0.38649975768888888890e-14 * t) * t) * t) * t) * t) * t;
return 0.25845480155298518485e-1 + (0.98459293067820123389e-3 + (0.57082915920051843672e-5 + (0.31613782169164830118e-7 + (0.16646478745529630813e-9 + (0.82840985928785407942e-12 + 0.38649975768888888890e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -217,7 +217,7 @@ double p15(double t) {
* @return result
*/
double p16(double t) {
return 0.27837754783474696598e-1 + (0.10078108563256892757e-2 + (0.59020366493792212221e-5 + (0.32979263553246520417e-7 + (0.17498524159268458073e-9 + (0.87622459124842525110e-12 + 0.41066206488888888890e-14 * t) * t) * t) * t) * t) * t;
return 0.27837754783474696598e-1 + (0.10078108563256892757e-2 + (0.59020366493792212221e-5 + (0.32979263553246520417e-7 + (0.17498524159268458073e-9 + (0.87622459124842525110e-12 + 0.41066206488888888890e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -227,7 +227,7 @@ double p16(double t) {
* @return result
*/
double p17(double t) {
return 0.29877251304899307550e-1 + (0.10318204245057349310e-2 + (0.61041829697162055093e-5 + (0.34414860359542720579e-7 + (0.18399863072934089607e-9 + (0.92703227366365046533e-12 + 0.43639844053333333334e-14 * t) * t) * t) * t) * t) * t;
return 0.29877251304899307550e-1 + (0.10318204245057349310e-2 + (0.61041829697162055093e-5 + (0.34414860359542720579e-7 + (0.18399863072934089607e-9 + (0.92703227366365046533e-12 + 0.43639844053333333334e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -237,7 +237,7 @@ double p17(double t) {
* @return result
*/
double p18(double t) {
return 0.31965587178596443475e-1 + (0.10566560976716574401e-2 + (0.63151633192414586770e-5 + (0.35924638339521924242e-7 + (0.19353584758781174038e-9 + (0.98102783859889264382e-12 + 0.46381060817777777779e-14 * t) * t) * t) * t) * t) * t;
return 0.31965587178596443475e-1 + (0.10566560976716574401e-2 + (0.63151633192414586770e-5 + (0.35924638339521924242e-7 + (0.19353584758781174038e-9 + (0.98102783859889264382e-12 + 0.46381060817777777779e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -247,7 +247,7 @@ double p18(double t) {
* @return result
*/
double p19(double t) {
return 0.34104450552588334840e-1 + (0.10823541191350532574e-2 + (0.65354356159553934436e-5 + (0.37512918348533521149e-7 + (0.20362979635817883229e-9 + (0.10384187833037282363e-11 + 0.49300625262222222221e-14 * t) * t) * t) * t) * t) * t;
return 0.34104450552588334840e-1 + (0.10823541191350532574e-2 + (0.65354356159553934436e-5 + (0.37512918348533521149e-7 + (0.20362979635817883229e-9 + (0.10384187833037282363e-11 + 0.49300625262222222221e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -257,7 +257,7 @@ double p19(double t) {
* @return result
*/
double p20(double t) {
return 0.36295603928292425716e-1 + (0.11089526167995268200e-2 + (0.67654845095518363577e-5 + (0.39184292949913591646e-7 + (0.21431552202133775150e-9 + (0.10994259106646731797e-11 + 0.52409949102222222221e-14 * t) * t) * t) * t) * t) * t;
return 0.36295603928292425716e-1 + (0.11089526167995268200e-2 + (0.67654845095518363577e-5 + (0.39184292949913591646e-7 + (0.21431552202133775150e-9 + (0.10994259106646731797e-11 + 0.52409949102222222221e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand All @@ -267,7 +267,7 @@ double p20(double t) {
* @return result
*/
double p21(double t) {
return 0.38540888038840509795e-1 + (0.11364917134175420009e-2 + (0.70058230641246312003e-5 + (0.40943644083718586939e-7 + (0.22563034723692881631e-9 + (0.11642841011361992885e-11 + 0.55721092871111111110e-14 * t) * t) * t) * t) * t) * t;
return 0.38540888038840509795e-1 + (0.11364917134175420009e-2 + (0.70058230641246312003e-5 + (0.40943644083718586939e-7 + (0.22563034723692881631e-9 + (0.11642841011361992885e-11 + 0.55721092871111111110e-14 * t) * t) * t) * t) * t) * t;
}

/**
Expand Down Expand Up @@ -1142,17 +1142,17 @@ static double p100() {


static double (* const table[])(const double) = {
p0, p1, p2, p3, p4, p5, p6, p7, p8, p9,
p10, p11, p12, p13, p14, p15, p16, p17, p18, p19,
p20, p21, p22, p23, p24, p25, p26, p27, p28, p29,
p30, p31, p32, p33, p34, p35, p36, p37, p38, p39,
p40, p41, p42, p43, p44, p45, p46, p47, p48, p49,
p50, p51, p52, p53, p54, p55, p56, p57, p58, p59,
p60, p61, p62, p63, p64, p65, p66, p67, p68, p69,
p70, p71, p72, p73, p74, p75, p76, p77, p78, p79,
p80, p81, p82, p83, p84, p85, p86, p87, p88, p89,
p90, p91, p92, p93, p94, p95, p96, p97, p98, p99,
p100
p0, p1, p2, p3, p4, p5, p6, p7, p8, p9,
p10, p11, p12, p13, p14, p15, p16, p17, p18, p19,
p20, p21, p22, p23, p24, p25, p26, p27, p28, p29,
p30, p31, p32, p33, p34, p35, p36, p37, p38, p39,
p40, p41, p42, p43, p44, p45, p46, p47, p48, p49,
p50, p51, p52, p53, p54, p55, p56, p57, p58, p59,
p60, p61, p62, p63, p64, p65, p66, p67, p68, p69,
p70, p71, p72, p73, p74, p75, p76, p77, p78, p79,
p80, p81, p82, p83, p84, p85, p86, p87, p88, p89,
p90, p91, p92, p93, p94, p95, p96, p97, p98, p99,
p100
};

/**
Expand All @@ -1169,12 +1169,12 @@ static double (* const table[])(const double) = {
*/

static double erfcxY100( const double y100 ) {
double t;
double(*f)(const double);
double t;
double(*f)(const double);

t = stdlib_base_floor( y100 );
f = table[ (int)t ];
return f( 2*y100 - ((2*t) + 1) );
t = stdlib_base_floor( y100 );
f = table[ (int)t ];
return f( 2*y100 - ((2*t) + 1) );
}


Expand Down Expand Up @@ -1218,12 +1218,12 @@ static double INV_SQRT_PI = 0.56418958354775628694807945156; // 1 / sqrt(pi);
*/

double stdlib_base_erfcx( const double x ) {
double x2;
double x2;

if( stdlib_base_is_nan(x) ) {
return x;
}
if ( x >= 0.0 ) {
if( stdlib_base_is_nan(x) ) {
return x;
}
if ( x >= 0.0 ) {
if ( x > 50.0 ) { // continued-fraction expansion is faster
if ( x > 5.0e7 ) { // 1-term expansion, important to avoid overflow
return INV_SQRT_PI / x;
Expand All @@ -1243,4 +1243,4 @@ double stdlib_base_erfcx( const double x ) {
return 2.0 * exp( x2 );
}
return ( 2.0*exp( x2 ) ) - erfcxY100( 400.0/(4.0-x) );
}
}