! Testing 3-value arithmetic ! ------------------------------------------------- ! A more ambitious project, integrating x**2 in [0,1] ! with a very simple algorithm. Official answer = 1/3. ! ! We are tackling here integer constants and variables. ! They are not supported directly by SEA (except with ! assignment statements), so we can show some useful ! workarounds. program test use sea3_arithmetic ! SEA top module type(sea_abs3) :: badint, x ! Declare vars call sea_check_precise() ! Verify numerics x = badint(10) ! call sea_write_entry(fout, "int(10) = ", x, 5) ! Write result call sea_write_nl(fout) ! Write a newline x = badint(100) ! call sea_write_entry(fout, "int(100) = ", x, 5) ! Write result call sea_write_nl(fout) ! Write a newline x = badint(1000) ! call sea_write_entry(fout, "int(1000) = ", x, 5) ! Write result call sea_write_nl(fout) ! Write a newline x = ONE / THREE call sea_write_entry(fout, "exact = ", x, 5) ! Write result call sea_write_nl(fout) ! Write a newline end program test function badint(nstep) use sea3_arithmetic ! SEA top module type(sea_abs3) :: badint integer :: nstep, i type(sea_abs3) :: sum, x, step x = ZERO ! 0.0 would work sum = ZERO ! 0.0 would work step = ONE / real(nstep, kind=PRECISE) ! 1.0/nstep would work do i = 0, nstep sum = sum + step * x**2 x = x + step end do badint = sum return end function badint