Skip to content

Commit

Permalink
revise is_nan
Browse files Browse the repository at this point in the history
  • Loading branch information
zaikunzhang committed Oct 6, 2023
1 parent afd3721 commit d3e12c0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions huge_value.f90 → huge.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module huge_value_mod
module huge_mod

implicit none
private
Expand Down Expand Up @@ -29,4 +29,4 @@ pure function huge_value_dp(x) result(y)
end function huge_value_dp


end module huge_value_mod
end module huge_mod
2 changes: 1 addition & 1 deletion inf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module inf_mod
! compilers are invoked with aggressive optimization flags, e.g., `gfortran -Ofast`.
! See infnan.f90 for more comments.

use, non_intrinsic :: huge_value_mod, only : huge_value
use, non_intrinsic :: huge_mod, only : huge_value
implicit none
private
public :: is_finite, is_inf, is_posinf, is_neginf
Expand Down
11 changes: 5 additions & 6 deletions infnan.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module infnan_mod
! 6. Even though the functions involve invocation of ABS and HUGE, their performance (in terms of
! CPU time) turns out comparable to or even better than the functions in `ieee_arithmetic`.

use, non_intrinsic :: huge_mod, only : huge_value
use, non_intrinsic :: inf_mod, only : is_finite, is_inf, is_posinf, is_neginf
implicit none
private
Expand All @@ -45,19 +46,17 @@ elemental pure function is_nan_sp(x) result(y)
implicit none
real(SP), intent(in) :: x
logical :: y
!y = (.not. (x <= huge_value(x) .and. x >= -huge_value(x))) .and. (.not. abs(x) > huge_value(x)) ! Does not always work
!y = (.not. (x < posinf(x) .and. x >= neginf(x))) .and. (.not. abs(x) >= posinf(x)) ! Does not always work
y = ((.not. is_finite(x)) .and. (.not. is_inf(x)))
y = (.not. (x <= huge_value(x) .and. x >= -huge_value(x))) .and. (.not. abs(x) > huge_value(x))
y = ((.not. is_finite(x)) .and. (.not. is_inf(x))) .or. y
end function is_nan_sp

elemental pure function is_nan_dp(x) result(y)
use consts_mod, only : DP
implicit none
real(DP), intent(in) :: x
logical :: y
!y = (.not. (x <= huge_value(x) .and. x >= -huge_value(x))) .and. (.not. abs(x) > huge_value(x)) ! Does not always work
!y = (.not. (x < posinf(x) .and. x >= neginf(x))) .and. (.not. abs(x) >= posinf(x)) ! Does not always work
y = ((.not. is_finite(x)) .and. (.not. is_inf(x)))
y = (.not. (x <= huge_value(x) .and. x >= -huge_value(x))) .and. (.not. abs(x) > huge_value(x))
y = ((.not. is_finite(x)) .and. (.not. is_inf(x))) .or. y
end function is_nan_dp


Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

.PHONY: test testd clean

SRC = ../consts.f90 ../huge_value.f90 ../inf.f90 ../infnan.f90 ieee_infnan.f90 testinfnan.f90 test.f90
SRC = ../consts.f90 ../huge.f90 ../inf.f90 ../infnan.f90 ieee_infnan.f90 testinfnan.f90 test.f90

test:
make -s 9test
Expand Down

0 comments on commit d3e12c0

Please sign in to comment.