program gpu_metal_18
! Nested arithmetic: polynomial evaluation
implicit none
integer, parameter :: n = 10000
real :: x(n), y(n), y_expected(n)
integer :: i

do i = 1, n
    x(i) = real(i) * 0.001
    y_expected(i) = 3.0 * x(i) ** 3 - 2.0 * x(i) ** 2 + 1.5 * x(i) - 0.5
end do

do concurrent (i = 1:n)
    y(i) = 3.0 * x(i) ** 3 - 2.0 * x(i) ** 2 + 1.5 * x(i) - 0.5
end do

do i = 1, n
    if (abs(y(i) - y_expected(i)) > 1.0e-2) error stop
end do

print *, "PASSED"
end program
