Skip to content

Commit efd6a71

Browse files
authored
Update Math.fround
小修
1 parent c122e66 commit efd6a71

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

docs/number.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,16 @@ Number.isInteger(true) // false
147147
```javascript
148148
3 === 3 + 2e-16 // true
149149
Number.isInteger(3.0000000000000002) // true
150-
// 3 的二进制 2 位,2e-16 的二进制最多能表示 51 位,第 3 ~ 53 位全为 0,直到第 55 位才开始出现 1,而这一位被丢弃了,误判为 true
150+
// 3 的二进制 2 位,2e-16 的二进制最多能表示 51 位
151+
// 第 3 ~ 53 位全为 0,直到第 55 位才开始出现 1,而这一位被丢弃了,误判为 true
151152

152153
3 + 4e-16 === 3 + 6e-16 // true
153154
Number.isInteger(3.0000000000000004) // false
154155
Number.isInteger(3.0000000000000006) // false
155156
// 第 51 位已为 1,且不会丢精度,所以 JavaScript 判定此数包含小数,返回 false
156157
```
157158

158-
数值的大小在 -1 与 1 之间(不含两个端点)时,其绝对值小于`Number.MIN_VALUE`即视为 0。
159+
数值的大小在 -1 与 1 之间(不含两个端点)时,其绝对值小于 `Number.MIN_VALUE` 即视为 0。
159160

160161
```javascript
161162
Number.MIN_VALUE // 5e-324
@@ -165,7 +166,7 @@ Number.isInteger(5e-325) // true
165166

166167
3e-324 === Number.MIN_VALUE // true
167168
Number.isInteger(3e-324) // false
168-
// 同样由于精度问题,即使是比`Number.MIN_VALUE`略小的数也会被判为 5e-324。
169+
// 同样由于精度问题,即使是比 Number.MIN_VALUE 略小的数也会被判为 5e-324。
169170
```
170171

171172
因此,在金融、天文等领域的数据精度要求较高、判断值是否整数的情况下,不建议使用`Number.isInteger()`原生函数,请使用包含正则的函数替代。
@@ -543,7 +544,7 @@ Math.imul(0x7fffffff, 0x7fffffff) // 1
543544
对于 -2 的 24 次方至 2 的 24 次方(不含两端)的整数,返回结果与参数本身一致。
544545

545546
```javascript
546-
Math.fround(0) // 0
547+
Math.fround(0) // 0
547548
Math.fround(1)   // 1
548549
Math.fround(2 ** 24 - 1) // 16777215
549550
```
@@ -568,7 +569,7 @@ Math.fround(0.7)   // 0.699999988079071
568569
Math.fround(1.0000000123) // 1
569570
```
570571

571-
对于 NaN 和 Infinity ,此方法返回原值。其它类型而言,`Math.fround` 方法会将其转为数值再返回单精度浮点数。
572+
对于 `NaN``Infinity`,此方法返回原值。其它类型而言,`Math.fround` 方法会将其转为数值再返回单精度浮点数。
572573

573574
```javascript
574575
Math.fround(NaN) // NaN

0 commit comments

Comments
 (0)