LCOV - code coverage report
Current view: top level - num/test/src - test_accurate_sum.f90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 21 21
Test Date: 2026-12-03 14:59:23 Functions: 100.0 % 3 3

            Line data    Source code
       1              : module test_accurate_sum
       2              : 
       3              :    use const_def, only: dp, qp
       4              :    use auto_diff, only: auto_diff_real_star_order1, assignment(=)
       5              :    use accurate_sum, only: accurate_real, assignment(=), operator(+)
       6              :    use accurate_sum_auto_diff_star_order1
       7              : 
       8              :    implicit none
       9              : 
      10              : contains
      11              : 
      12            1 :    subroutine run_test_accurate_sum()
      13              : 
      14            1 :       call test_double_precision_addition()
      15            1 :       call test_quad_precision_addition()
      16              : 
      17            1 :    end subroutine run_test_accurate_sum
      18              : 
      19            3 :    subroutine test_double_precision_addition()
      20              :       real(dp), parameter :: expected = 1d0
      21              :       type(auto_diff_real_star_order1) :: term, res
      22              :       type(accurate_auto_diff_real_star_order1) :: sum
      23              : 
      24              :       ! The auto_diff version of compensated summation uses double precision.
      25            1 :       term = 1d40
      26            1 :       sum = term
      27            1 :       term = 1d0
      28            1 :       sum = sum + term
      29            1 :       term = -1d40
      30            1 :       sum = sum + term
      31            1 :       res = sum
      32              : 
      33              :       write (*, '(a40, 1pd26.16, a7, 1pd26.16)') &
      34            1 :          'compensated addition expected', expected, 'got', res%val
      35              : 
      36            1 :    end subroutine test_double_precision_addition
      37              : 
      38            2 :    subroutine test_quad_precision_addition()
      39              :       real(qp), parameter :: expected = 1.0_qp
      40              :       real(qp) :: res
      41              :       type(accurate_real) :: sum
      42              : 
      43            1 :       sum = 1.e40_qp
      44            1 :       sum = sum + 1.0_qp
      45            1 :       sum = sum + (-1.e40_qp)
      46            1 :       res = sum
      47              : 
      48              :       write (*, '(a40, 1pd26.16, a7, 1pd26.16)') &
      49            1 :          'compensated addition qp expected', expected, 'got', res
      50              : 
      51            1 :    end subroutine test_quad_precision_addition
      52              : 
      53              : end module test_accurate_sum
        

Generated by: LCOV version 2.0-1