almost(3f) - [M_framework__approx] return true or false if two numbers agree up to specified number of digits (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
elemental impure function almost(x,y,digits,verbose)
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 number of digits of precision to compare. May be INTEGER or REAL. 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_framework__approx, 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,i,verbose=.true.) write(*,*)i,z enddo end program demo_almostResults:
> *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 ... > digits out of requested 1.00000000 > 1 T > *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 ... > digits out of requested 2.00000000 > 2 T > *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 ... > digits out of requested 3.00000000 > 3 F > *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 ... > digits out of requested 4.00000000 > 4 F > *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 ... > digits out of requested 5.00000000 > 5 F > *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 ... > digits out of requested 6.00000000 > 6 F > *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 ... > digits out of requested 7.00000000 > 7 F > *sp_accdig* significant digit request too high= 8.00000000 > *almost* for values 1.23456776 1.23000002 agreement of 2.43020344 ... > digits out of requested 8.00000000 > 8 F
John S. Urban
Public Domain
Nemo Release 3.1 | almost (3) | February 23, 2025 |