! Testing 3-value arithmetic ! ------------------------------------------------------- ! We are computing a 2nd order polynomial in 3 ways: ! ! * directly from the formula ! * via Horner Rule ! * with a procedure that is not subject ! to the multiple instance problem ! ! The polynomial 1 - 2*x + x**2 = (x - 1) ** 2 have a ! double root at x = 1.0. There is a minimum there and ! it touches the x-axis. Note that we get a much smaller ! error range in the third way. ! ! We can see that the main problem with BSA computation, ! lack of monotonicity can be sneaky. program test use sea3_arithmetic ! SEA top module type(sea_abs3) :: x, y ! Declare vars call sea_check_precise() ! Verify numerics ! x = sea_abs3(1.0E-3, 2.0, 1.0E-3) x = sea_abs3(1.0E-3, 1.0, 1.0E-3) call sea_write_entry(fout, "x = ", x, 13) ! Write result call sea_write_nl(fout) ! Write a newline y = ONE - TWO * x + ONE * (x**2) call sea_write_entry(fout, "direct = ", y, 13) ! Write result call sea_write_nl(fout) ! Write a newline y = ONE - (TWO - ONE * x) * x call sea_write_entry(fout, "horner = ", y, 13) ! Write result call sea_write_nl(fout) ! Write a newline y = sea_polynom(x, ONE, -TWO, ONE) call sea_write_entry(fout, "poly2 = ", y, 13) ! Write result call sea_write_nl(fout) ! Write a newline end program test