Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: operators/bit 关于取整性能谁更快的描述,并不是否否最快 #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mzvast wants to merge 1 commit into wangdoc:master from mzvast:master
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/operators/bit.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ toInt32(Math.pow(2, 32) - 1) // -1

位运算只对整数有效,遇到小数时,会将小数部分舍去,只保留整数部分。所以,将一个小数与`0`进行二进制或运算,等同于对该数去除小数部分,即取整数位。

使用二进制或运算取整,是所有取整方法中最快的一种。

```javascript
2.9 | 0 // 2
-2.9 | 0 // -2
Expand Down Expand Up @@ -110,7 +112,6 @@ toInt32(Math.pow(2, 32) - 1) // -1
~~3 // 3
```

使用二进制否运算取整,是所有取整方法中最快的一种。

对字符串进行二进制否运算,JavaScript 引擎会先调用`Number`函数,将字符串转为数值。

Expand Down

AltStyle によって変換されたページ (->オリジナル) /