curve fit algorithm from graphics gems test app (mac-osx)