科学计算器对数体系:log 是常用对数(log10)、ln 是自然对数
# 科学计算器对数体系:log 是常用对数(log10)、ln 是自然对数
> 接口 免费科学计算器(apiCode 1699)· 接入点 科学计算器(1699-1)· 免费 · POST/GET · 返回 JSON · 适合 学生 / 开发者 / 科研 · 阅读约 3 分钟
## 核心要点
- `log` = **常用对数(以 10 为底)**:`log(100)=2`、`log(1000)=3`。
- `ln` = **自然对数(以 e 为底)**:`ln(10)=2.3026`、`ln(1)=0`。
- 两者都是单参数,直接传真数即可;不要混淆底数。
## Why:为什么这个区分很重要
教材里「log」有时指常用对数、有时指自然对数,容易混。实测确认本接口的 `log` 就是**以 10 为底**的常用对数,`ln` 才是自然对数。用错一个字母,结果差一个数量级(如 `log(10)=1` 而 `ln(10)=2.3026`),做工程或科研计算时尤其要分清。
## What:接口速览
| 项目 | 说明 |
|------|------|
| 请求地址 | `https://route.showapi.com/1699-1?appKey={your_appKey}` |
| 相关操作名 | `log`(常用对数)、`ln`(自然对数)、`exp`(e 的指数) |
| 计费 | 免费,[使用档次限制](https://www.showapi.com/free-api) |
## How:正确写法
```python
import requests
APP_KEY = "YOUR_APPKEY"
def calc(num, op):
r = requests.post(
"https://route.showapi.com/1699-1",
params={"appKey": APP_KEY},
data={"num": num, "operation": op, "rad_or_ang": ""},
timeout=10
)
b = r.json()["showapi_res_body"]
return b["result"] if str(b.get("ret_code")) == "0" else f"失败: {b.get('remark')}"
print(calc("100", "log")) # 2.0 常用对数 log10(100)
print(calc("10", "ln")) # 2.302585 自然对数 ln(10)
print(calc("1", "exp")) # 2.71828 e^1
```
### cURL
```bash
curl -X POST "https://route.showapi.com/1699-1?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded" \
-d "num=100&operation=log&rad_or_ang="
```
## 返回示例与解析
| 调用 | 真实结果 | 含义 |
|------|---------|------|
| `log(100)` | `2.0` | log₁₀(100) = 2 |
| `log(1000)` | `2.9999999999999996` | log₁₀(1000) ≈ 3(浮点尾差) |
| `ln(10)` | `2.302585092994046` | 自然对数 ln(10) |
| `ln(1)` | `0.0` | ln(1) = 0 |
| `exp(1)` | `2.718281828459045` | e¹ |
## 进阶 / 边界
- **要换底数**:用换底公式 `log_a(x) = ln(x) / ln(a)`,本接口没有直接的「任意底数对数」,可用 `ln` 组合实现。
- **浮点尾差**:`log(1000)` 会返回 `2.99999…`,展示时按精度四舍五入。
## FAQ
**Q1:`log` 到底以几为底?**
以 10 为底(常用对数)。`log(100)=2`。
**Q2:要自然对数用哪个?**
用 `ln`。`ln(10)=2.3026`。
**Q3:能算任意底数(如 log₂8)吗?**
接口没有直接操作名,用换底公式:`ln(8) / ln(2)` 自行计算。
**Q4:指数函数怎么算?**
用 `exp`,`exp(1)=e≈2.71828`。
## 相关能力 / 下一步阅读
- [科学计算器操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699) —— 全部 32 个操作名
- [科学计算器幂与根用法](https://www.showapi.com/guides/calculator-power-root-1699) —— `square` / `sqrt` 多参数
- [科学计算器三角函数角度制实战](https://www.showapi.com/guides/calculator-trig-angles-1699) —— 角度制单位
- **本系列共 11 篇**:查看[科学计算器开发指南总目录](https://www.showapi.com/guides/calculator-guides-1699)