import math


def clamping_acos(cos):
    """
    Calculate arccos with its argument clamped to [-1, 1]
    """
    if cos > 1:
        return 0
    if cos < -1:
        return math.pi/2
    return math.acos(cos)