Files

28 lines
598 B
Python

"""迷你计算库 —— dim4 fixture(已修复版本,供自检使用)。"""
from __future__ import annotations
def add(a: float, b: float) -> float:
return a + b
def div(a: float, b: float) -> float:
if b == 0:
raise ValueError("divisor must not be zero")
return a / b
def average(values: list[float]) -> float:
if not values:
return 0.0
return sum(values) / len(values)
def clamp(value: float, lo: float, hi: float) -> float:
if value < lo:
return lo
if value > hi:
return hi
return value