- Notifications
You must be signed in to change notification settings - Fork 197
[stdlib_math] add is_close routines. #488
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
Changes from all commits
Commits
Show all changes
18 commits Select commit Hold shift + click to select a range
d395740 add `is_close` in `stdlib_math`.
zoziha 9cebec7 Fix a warning in `arange` and avoid type conversion.
zoziha 909d492 Merge branch 'master' into add_close
zoziha 7c8a8fb Merge branch 'master' into add_close
zoziha c3d0bdd Update stdlib_math.is_close, like python math.isclose
zoziha 71021bb Merge branch 'master' into add_close
zoziha f9acfbe Fix src/makefile.manual
zoziha e583de5 Merge branch 'add_close' of https://github.com/fortran-fans/stdlib in…
zoziha d477d5a Add `all_close` function in `stdlib_math`.
zoziha 6fe1529 Merge branch 'master' into add_close
zoziha 064e7f3 Change the `all_close` implementation: gcc9 not support `select rank`.
zoziha 7e36e58 Merge branch 'add_close' of https://github.com/fortran-fans/stdlib in…
zoziha 122837d Add `pure` label for `all_close`.
zoziha 6eb25dd Merge branch 'master' into add_close
zoziha adfb820 Add `equal_nan` argument,
zoziha 53874c9 Merge branch 'master' into add_close
zoziha 268cedc Update tests for **_close,
zoziha 549ee96 Remove old tests for **_close.
zoziha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,25 @@ | ||
| #:include "common.fypp" | ||
| #:set RANKS = range(1, MAXRANK + 1) | ||
| #:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES | ||
| | ||
| submodule (stdlib_math) stdlib_math_all_close | ||
| | ||
| implicit none | ||
| | ||
| contains | ||
| | ||
| #:for k1, t1 in RC_KINDS_TYPES | ||
| #:for r1 in RANKS | ||
| logical pure module function all_close_${r1}$_${t1[0]}$${k1}$(a, b, rel_tol, abs_tol, equal_nan) result(close) | ||
| | ||
| ${t1}$, intent(in) :: a${ranksuffix(r1)}$, b${ranksuffix(r1)}$ | ||
| real(${k1}$), intent(in), optional :: rel_tol, abs_tol | ||
| logical, intent(in), optional :: equal_nan | ||
| | ||
| close = all(is_close(a, b, rel_tol, abs_tol, equal_nan)) | ||
| | ||
| end function all_close_${r1}$_${t1[0]}$${k1}$ | ||
| #:endfor | ||
| #:endfor | ||
| | ||
| end submodule stdlib_math_all_close |
This file contains hidden or 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
This file contains hidden or 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,47 @@ | ||||||
| #:include "common.fypp" | ||||||
| | ||||||
| submodule(stdlib_math) stdlib_math_is_close | ||||||
| | ||||||
| use, intrinsic :: ieee_arithmetic, only: ieee_is_nan | ||||||
| implicit none | ||||||
| | ||||||
| #:for k1 in REAL_KINDS | ||||||
| real(${k1}$), parameter :: sqrt_eps_${k1}$ = sqrt(epsilon(1.0_${k1}$)) | ||||||
| #:endfor | ||||||
| | ||||||
| contains | ||||||
| | ||||||
| #! Determines whether the values of `a` and `b` are close. | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggested change
| ||||||
| | ||||||
| #:for k1, t1 in REAL_KINDS_TYPES | ||||||
| elemental module logical function is_close_${t1[0]}$${k1}$(a, b, rel_tol, abs_tol, equal_nan) result(close) | ||||||
| ${t1}$, intent(in) :: a, b | ||||||
| real(${k1}$), intent(in), optional :: rel_tol, abs_tol | ||||||
| logical, intent(in), optional :: equal_nan | ||||||
| logical :: equal_nan_ | ||||||
| | ||||||
| equal_nan_ = optval(equal_nan, .false.) | ||||||
| | ||||||
| if (ieee_is_nan(a) .or. ieee_is_nan(b)) then | ||||||
| close = merge(.true., .false., equal_nan_ .and. ieee_is_nan(a) .and. ieee_is_nan(b)) | ||||||
| else | ||||||
| close = abs(a - b) <= max( abs(optval(rel_tol, sqrt_eps_${k1}$)*max(abs(a), abs(b))), & | ||||||
| abs(optval(abs_tol, 0.0_${k1}$)) ) | ||||||
| end if | ||||||
| | ||||||
| end function is_close_${t1[0]}$${k1}$ | ||||||
| #:endfor | ||||||
| | ||||||
| #:for k1, t1 in CMPLX_KINDS_TYPES | ||||||
| elemental module logical function is_close_${t1[0]}$${k1}$(a, b, rel_tol, abs_tol, equal_nan) result(close) | ||||||
| ${t1}$, intent(in) :: a, b | ||||||
| real(${k1}$), intent(in), optional :: rel_tol, abs_tol | ||||||
| logical, intent(in), optional :: equal_nan | ||||||
| | ||||||
| close = is_close_r${k1}$(a%re, b%re, rel_tol, abs_tol, equal_nan) .and. & | ||||||
| is_close_r${k1}$(a%im, b%im, rel_tol, abs_tol, equal_nan) | ||||||
| | ||||||
| end function is_close_${t1[0]}$${k1}$ | ||||||
| #:endfor | ||||||
| | ||||||
| end submodule stdlib_math_is_close | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.