Calculate PI function.