added clamp function and M_PI constant