calculate function