2022-08-23 10:12:36 +08:00
|
|
|
## 扩展数学函数
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 1.d2r
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> 将角度转换成弧度,传入参数单位是角度。
|
2021-01-09 17:30:54 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
d2r(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(d2r(7));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 2.r2d
|
|
|
|
|
|
|
|
> 将弧度转换成角度,传入参数单位是弧度。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
r2d(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
r2d(7)
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 3.sin
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> sin 函数,传入参数单位是弧度。
|
2021-01-09 17:30:54 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
sin(a) => double
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 示例
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
print(sin(0));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
### 4.cos
|
|
|
|
|
|
|
|
> cos 函数,传入参数单位是弧度。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
2021-01-13 14:04:50 +08:00
|
|
|
cos(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(cos(0));
|
|
|
|
```
|
|
|
|
|
|
|
|
### 5.tan
|
|
|
|
|
|
|
|
> tan 函数,传入参数单位是弧度。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
tan(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(tan(1));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 6.asin
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> asin 函数,传入参数单位是弧度。
|
2021-01-09 17:30:54 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
asin(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(asin(1));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 7.acos
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> acos 函数,传入参数单位是弧度。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
acos(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(acos(1));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 8.atan
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> atan 函数,传入参数单位是弧度。
|
2021-01-09 17:30:54 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
atan(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(atan(1));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 9.atan2
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> atan2 函数,传入参数单位是弧度。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
atan2(a, b) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(atan2(2, 3));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 10.sin_deg
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> sin_deg 函数,传入参数单位是角度。
|
2021-01-09 17:30:54 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
sin_deg(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(sin_deg(45));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 11.cos_deg
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> cos_deg 函数,传入参数单位是角度。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
cos_deg(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(cos_deg(45));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 12.tan_deg
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> tan_deg 函数,传入参数单位是角度。
|
2021-01-09 17:30:54 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
tan_deg(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(tan_deg(30));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 13.asin_deg
|
|
|
|
|
|
|
|
> asin_deg 函数,传入参数单位是角度。
|
|
|
|
----------------------------
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
asin_deg(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(asin_deg(45));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 14.acos_deg
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> acos_deg 函数,传入参数单位是角度。
|
2021-01-09 17:30:54 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
acos_deg(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(acos_deg(45));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 15.atan_deg
|
|
|
|
|
|
|
|
> atan_deg 函数,传入参数单位是角度。
|
|
|
|
----------------------------
|
2021-01-09 17:30:54 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
atan_deg(a) => double
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(atan_deg(30));
|
2021-01-09 17:30:54 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 16.atan2_deg
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> atan2_deg 函数,传入参数单位是弧度。
|
2021-07-16 10:01:33 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
atan2_deg(a, b) => double
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(atan2_deg(20, 30));
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 17.exp
|
|
|
|
|
|
|
|
> exp 函数
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
exp(a) => double
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(exp(7));
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 18.sqrt
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> sqrt 函数。
|
2021-07-16 10:01:33 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
sqrt(a) => double
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(sqrt(2));
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 19.pow
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> pow 函数。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
pow(a, b) => double
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(pow(2, 3));
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 20.log10
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> log10 函数。
|
2021-07-16 10:01:33 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
log10(a) => double
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(log10(9));
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 21.logf
|
|
|
|
|
|
|
|
> logf 函数。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
logf(a) => double
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(logf(0));
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 22.pow10
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> pow10 函数。
|
2021-07-16 10:01:33 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
pow10(a) => double
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(pow10(2));
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 23.is_prime
|
2021-07-16 10:01:33 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> 是否为质数。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
is_prime(a) => bool
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(is_prime(7));
|
2021-07-16 10:01:33 +08:00
|
|
|
```
|
2021-07-20 11:24:38 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 24.is_int
|
2021-07-20 11:24:38 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> 是否为整数。
|
2021-07-20 11:24:38 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-07-20 11:24:38 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
is_int(a) => bool
|
2021-07-20 11:24:38 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(is_int(7));
|
2021-07-20 11:24:38 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 25.is_odd
|
2021-07-20 11:24:38 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> 是否为奇数。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
is_odd(a) => bool
|
2021-07-20 11:24:38 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(is_odd(7));
|
2021-07-20 11:24:38 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 26.is_even
|
2021-07-20 11:29:05 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
> 是否为偶数。
|
2021-07-20 11:29:05 +08:00
|
|
|
----------------------------
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
2021-07-20 11:29:05 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
```js
|
|
|
|
is_even(a) => bool
|
2021-07-20 11:29:05 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(is_even(7));
|
2021-07-20 11:29:05 +08:00
|
|
|
```
|
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
### 27.is_negative
|
|
|
|
|
|
|
|
> 是否为负数。
|
|
|
|
----------------------------
|
2021-07-20 11:29:05 +08:00
|
|
|
|
2022-08-23 10:12:36 +08:00
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
is_negative(a) => bool
|
2021-07-20 11:29:05 +08:00
|
|
|
```
|
2022-08-23 10:12:36 +08:00
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(is_negative(7));
|
|
|
|
```
|
|
|
|
|
|
|
|
### 28.is_positive
|
|
|
|
|
|
|
|
> 是否为正数。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
|
|
|
is_positive(a) => bool
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(is_positive(7));
|
|
|
|
```
|
|
|
|
|
|
|
|
### 29.random0to1
|
|
|
|
|
|
|
|
> 生成一个0到1之间的随机数。
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
#### 原型
|
|
|
|
|
|
|
|
```js
|
2024-08-14 11:37:38 +08:00
|
|
|
random0to1() => double
|
2022-08-23 10:12:36 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
#### 示例
|
|
|
|
|
|
|
|
```js
|
|
|
|
print(random0to1());
|
2021-07-20 11:29:05 +08:00
|
|
|
```
|