| 函式名稱 | 功能描述 | 範例 |
|---|---|---|
sqrt(x) |
開根號,僅適用於 x ≥ 0 | sqrt(9.0) → 3.0 |
pow(x, y) |
計算 x 的 y 次方 | pow(2.0, 3.0) → 8.0 |
abs(x) |
計算整數的絕對值 | abs(-5) → 5 |
fabs(x) |
計算浮點數的絕對值 | fabs(-3.2) → 3.2 |
ceil(x) |
向上取整(天花板函式) | ceil(2.3) → 3.0 |
floor(x) |
向下取整(地板函式) | floor(2.9) → 2.0 |
round(x) |
四捨五入 | round(2.5) → 3.0 |
fmod(x, y) |
求浮點數 x 除以 y 的餘數 | fmod(5.3, 2.0) → 1.3 |
hypot(x, y) |
計算 √(x² + y²),常用於畢氏定理 | hypot(3.0, 4.0) → 5.0 |
Created
July 26, 2025 08:52
-
-
Save senina4/f233f71fd28f19f2c96184ada91cb8b8 to your computer and use it in GitHub Desktop.
常用 `cmath` 函式
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment