class ExponentialFilter:
    def __init__(self, alpha):
        self.alpha = max(0.0, min(1.0, float(alpha)))
        self.value = 0.0
        self.initialized = False

    def update(self, sample):
        sample = float(sample)
        if not self.initialized:
            self.value = sample
            self.initialized = True
        else:
            self.value = self.alpha * sample + (1.0 - self.alpha) * self.value
        return self.value

    def reset(self):
        self.value = 0.0
        self.initialized = False


def clamp(value, min_value, max_value):
    return max(min_value, min(max_value, value))

