当前位置:网站首页>What does the expression > > 0 in JS mean
What does the expression > > 0 in JS mean
2022-07-29 00:19:00 【Nanchang pengyuyan】
At development time , See a statistic used >>> expression
The code is as follows
<el-table-column prop="planFunds" min-width="160" header-align="center" align="center" show-overflow-tooltip label=" Total budget price ">
<template slot-scope="scope">
{
{ fmoney((scope.row.planNumber>>>0)*(scope.row.marketTaxPrice>>>0)) }}
</template>
</el-table-column>
First of all, baidu Dafa :
Checked MDN original >>> It's an unsigned right shift ,>> Is a signed shift
It turned out to be a shift operator , Belong to es6 grammar , No wonder not ,>>> It's also called logical shift right , If the number is positive , Then the high position will be supplemented 0, And if the number is negative , After moving right, the high position will be filled as well 0. that >>> 0 What does it stand for ?
No sign shift : This operator moves the first operand to the right by the specified number of bits . Bits shifted to the right are discarded , On the left 0 fill . Because the sign bit becomes 0, So the results are always nonnegative .( Even if you move right 0 A bit , The results are also nonnegative .)
- According to the documentation, even if you move 0 Bits can also turn a negative number into a positive number , You can even turn a decimal into an integer , Convert undefined values to 0.
I checked some information , among stackoverflow There is a high vote in it , There is a saying in it :
It doesn’t just convert non-Numbers to Number, it converts them to Numbers that can be expressed as 32-bit unsigned ints.
The original shift operator did two conversions before shift , The first will not be number Type of data to number, Second will number Convert to unsigned 32bit data , That is to say Uint32 type . These are independent of the number of bits shifted , displacement 0 Bit is mainly used js The first two transformations are made for the internal characteristics of .
- that Uint32 How types are converted ?
1. If it cannot be converted to Number, That's for 0
2. If it is non integer , Convert to integer first , Refer to the formula sign(n) ⋅ floor(abs(n))
function ToInteger(x) {
x = Number(x);
return x < 0 ? Math.ceil(x) : Math.floor(x);
}
3. If it's a positive number , Return positive number , If it's a negative number , Return negative + 2 Of 32 Power
function modulo(a, b) {
return a - Math.floor(a/b)*b;
}
function ToUint32(x) {
return modulo(ToInteger(x), Math.pow(2, 32));
}
Reference article :Integers and shift operators in JavaScript
- summary
x >>> 0 It is essentially a guarantee x meaningful ( Is numeric type ), And is a positive integer , Within the range of valid arrays (0 ~ 0xFFFFFFFF), And the default value is 0. A small expression , There are multiple exception handling hidden .js That's weird .
边栏推荐
- vulnhub:SolidState
- Sword finger offer 64. find 1+2+... +n, logical operator short circuit effect
- [TA frost wolf \u may - "hundred people plan"] Figure 3.6 texture compression - inclusion slimming
- Centos7 install mysql8
- [TA frost wolf _may- "hundred people plan"] art 2.2 model basis
- Doip test development practice
- Immutable x officially opens IMX token pledge detailed IMX pledge introduction optimistic about the development prospect of IMX
- 【C】 Introduction and Simulation Implementation of ATOI and offsetof
- 2022网络安全学习路线 非常详细 推荐学习
- Advanced area of attack and defense world web masters warmup
猜你喜欢
Do like and in indexes in MySQL go
Using recursion and chain header interpolation to realize the group turnover of linked lists -- leetcode25 K group turnover linked lists
Real time data warehouse: Netease strictly selects the practice of real-time data warehouse based on Flink
centos7安装mysql8
SQL实现将多行记录合并成一行
[microservice] Nacos cluster building and loading file configuration
"Method not allowed", 405 problem analysis and solution
Intelligent trash can (VII) -- Introduction and use of sg90 steering gear (Pico implementation of raspberry pie)
The difference between {} and ${}
Es6操作教程
随机推荐
Real time data warehouse: Netease strictly selects the practice of real-time data warehouse based on Flink
Simple use and understanding of laravel message queue
Geth installation
CV semantic segmentation model sketch (2)
VS2005 accesses the setting method "recommended collection" of vss2005 through sourceoffsite
Oracle create tablespaces and users
动态规划问题(八)
Doip test development practice
Yolov5 learning notes (I) -- principle overview
Review of categories 1-4
Applet verification code login
Android studio connects to MySQL and completes simple login and registration functions
Install MySQL using Yum for Linux
How can Plato obtain premium income through elephant swap in a bear market?
@Detailed explanation of the use of transactional annotation
12个MySQL慢查询的原因分析
Attack and defense world web master advanced area PHP_ rce
Newscenter, advanced area of attack and defense world web masters
MySQL的存储过程
1-7 solve the problem of this pointing of methods in classes