Changeset 4568 for palm/trunk/UTIL/inifor/src/inifor_util.f90
- Timestamp:
- Jun 19, 2020 11:56:30 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/UTIL/inifor/src/inifor_util.f90
r4523 r4568 26 26 ! ----------------- 27 27 ! $Id$ 28 ! Added function for checking floating point equality 29 ! 30 ! 31 ! 4523 2020-05-07 15:58:16Z eckhard 28 32 ! respect integer working precision (iwp) specified in inifor_defs.f90 29 33 ! … … 462 466 END SUBROUTINE 463 467 468 469 !------------------------------------------------------------------------------! 470 ! Description: 471 ! ------------ 472 !> Check for exact or near equality of two floating point numbers. Inspired by 473 !> https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ 474 !------------------------------------------------------------------------------! 475 LOGICAL FUNCTION nearly_equal(a, b, max_rel_diff) 476 477 REAL(wp), INTENT(IN) :: a, b, max_rel_diff 478 REAL(wp) :: diff, mag 479 480 diff = ABS( a - b ) 481 mag = MAX( ABS(a), ABS(b) ) 482 nearly_equal = ( diff .LE. mag * max_rel_diff ) 483 484 END FUNCTION nearly_equal 485 464 486 END MODULE inifor_util
Note: See TracChangeset
for help on using the changeset viewer.