-
-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add support for ratios evaluating as infinity in `math/base…
…/tools/evalrational-compile-c` PR-URL: #1970 Ref: #1834 (comment) Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
- Loading branch information
Showing
8 changed files
with
1,270 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...base/tools/evalrational-compile-c/test/fixtures/coefficient_ratio_negative_infinity.c.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Evaluates a rational function. | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static double evalrational() { | ||
return -1.0 / 0.0; | ||
} |
9 changes: 9 additions & 0 deletions
9
...ols/evalrational-compile-c/test/fixtures/coefficient_ratio_negative_infinity_custom.c.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Evaluates a rational function. | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static float rational123() { | ||
return -1.0f / 0.0f; | ||
} |
9 changes: 9 additions & 0 deletions
9
...base/tools/evalrational-compile-c/test/fixtures/coefficient_ratio_positive_infinity.c.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Evaluates a rational function. | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static double evalrational() { | ||
return 1.0 / 0.0; | ||
} |
9 changes: 9 additions & 0 deletions
9
...ols/evalrational-compile-c/test/fixtures/coefficient_ratio_positive_infinity_custom.c.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* Evaluates a rational function. | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static float rational123() { | ||
return 1.0f / 0.0f; | ||
} |
36 changes: 36 additions & 0 deletions
36
..._modules/@stdlib/math/base/tools/evalrational-compile-c/test/fixtures/evalrational4.c.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)). | ||
* | ||
* ## Notes | ||
* | ||
* - Coefficients should be sorted in ascending degree. | ||
* - The implementation uses [Horner's rule][horners-method] for efficient computation. | ||
* | ||
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method | ||
* | ||
* @param x value at which to evaluate the rational function | ||
* @return evaluated rational function | ||
*/ | ||
static double evalrational( const double x ) { | ||
double ax; | ||
double ix; | ||
double s1; | ||
double s2; | ||
if ( x == 0.0 ) { | ||
return -1.0 / 0.0; | ||
} | ||
if ( x < 0.0 ) { | ||
ax = -x; | ||
} else { | ||
ax = x; | ||
} | ||
if ( ax <= 1.0 ) { | ||
s1 = -1.0 + (x * (2.5 + (x * (3.14 + (x * -1.0))))); | ||
s2 = 0.0 + (x * (-3.5 + (x * (2.2 + (x * 1.25))))); | ||
} else { | ||
ix = 1.0 / x; | ||
s1 = -1.0 + (ix * (3.14 + (ix * (2.5 + (ix * -1.0))))); | ||
s2 = 1.25 + (ix * (2.2 + (ix * (-3.5 + (ix * 0.0))))); | ||
} | ||
return s1 / s2; | ||
} |
Oops, something went wrong.
f36b80d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
The above coverage report was generated for the changes in this push.