By the way, your function works correctly on a 2008 R2 functional domain.