almost(3f) - [M_verify] return true or false if two numbers agree up to specified number of digits (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
function almost(x,y,digits)
class(*),intent(in) :: x,y class(*),intent(in) :: rdigits logical,intent(in),optional :: verbose logical :: almost
Returns true or false depending on whether the two numbers given agree to within the specified number of digits as calculated by ACCDIG(3f).
x,y expected and calculated values to be compared. May be of type REAL, INTEGER, or DOUBLEPRECISION. rdigits real number representing number of digits of precision to compare verbose optional value that specifies to print the results of the comparison when set to .TRUE..
almost TRUE if the input values compare up to the specified number of values
sample:
program demo_almost use M_verify, only : almost implicit none real :: x, y logical :: z integer :: i x=1.2345678 y=1.2300000 do i=1,8 z=almost(x,y,real(i),verbose=.true.) write(*,*)i,z enddo end program demo_almostoutput:
*almost* for values 1.23456776 1.23000002 agreement of 2.43020344 digits out of requested 1.0 1 T *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 digits out of requested 2.0 2 T *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 digits out of requested 3.0 3 F *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 digits out of requested 4.0 4 F *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 digits out of requested 5.0 5 F *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 digits out of requested 6.0 6 F *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 digits out of requested 7.0 7 F *accdig* significant digit request too high= 8.00000000 *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 digits out of requested 8.0 8 F
John S. Urban
Public Domain
Nemo Release 3.1 | almost (3) | February 23, 2025 |