Skip to content

Commit

Permalink
Fix comparison of two real numbers for equality
Browse files Browse the repository at this point in the history
  • Loading branch information
gha3mi committed Jan 26, 2024
1 parent 78b66c9 commit 020eb84
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/fordiff.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end function f
end interface

! Check for potential division by zero
if (h == 0.0_rk) error stop 'Division by zero. Please provide a non-zero value for h.'
if (abs(h)<tiny(0.0_rk)) error stop 'Division by zero. Please provide a non-zero value for h.'

dfdx = aimag(f(cmplx(x, h, rk))) / h

Expand Down Expand Up @@ -72,7 +72,7 @@ impure function f(z) result(fz)
end function f
end interface

if (h == 0.0_rk) error stop 'Division by zero. Please provide a non-zero value for h.'
if (abs(h)<tiny(0.0_rk)) error stop 'Division by zero. Please provide a non-zero value for h.'

do i = 1, size(x)
temp_x = 0.0_rk
Expand Down Expand Up @@ -106,7 +106,7 @@ end function f

allocate(dfdx(size(f(cmplx(x,kind=rk))),size(x)))

if (h == 0.0_rk) error stop 'Division by zero. Please provide a non-zero value for h.'
if (abs(h)<tiny(0.0_rk)) error stop 'Division by zero. Please provide a non-zero value for h.'

do i = 1, size(x)
temp_x = 0.0_rk
Expand Down Expand Up @@ -137,7 +137,7 @@ impure function f(z) result(fz)
end function f
end interface

if (h == 0.0_rk) error stop 'Division by zero. Please provide a non-zero value for h.'
if (abs(h)<tiny(0.0_rk)) error stop 'Division by zero. Please provide a non-zero value for h.'

select case (method)
case('forward')
Expand Down Expand Up @@ -243,7 +243,7 @@ impure function f(z) result(fz)
end function f
end interface

if (h == 0.0_rk) error stop 'Division by zero. Please provide a non-zero value for h.'
if (abs(h)<tiny(0.0_rk)) error stop 'Division by zero. Please provide a non-zero value for h.'

select case (method)
case('forward')
Expand Down Expand Up @@ -367,7 +367,7 @@ impure function f(z) result(fz)
end function f
end interface

if (h == 0.0_rk) error stop 'Division by zero. Please provide a non-zero value for h.'
if (abs(h)<tiny(0.0_rk)) error stop 'Division by zero. Please provide a non-zero value for h.'

select case (method)
case('forward')
Expand Down

0 comments on commit 020eb84

Please sign in to comment.