當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript中正负零
生活随笔
收集整理的這篇文章主要介紹了
JavaScript中正负零
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
JavaScript中正負零
判斷正負零
//判斷是否為+0 function isPositiveZero(num){return num === 0 && 1 / num > 0 } //判斷是否為-0 function isNegativeZero(num){return num === 0 && 1 / num < 0 }正負零的加減運算
+0 + (+0) = +0 +0 + (-0) = +0 -0 + (+0) = +0 -0 + (-0) = -0 +0 - (+0) = +0 +0 - (-0) = +0 -0 - (+0) = -0 -0 - (-0) = +0驗證
isPositiveZero(+0 + (+0)) //ture isPositiveZero(+0 + (-0)) //ture isPositiveZero(-0 + (+0)) //ture isPositiveZero(-0 + (-0)) //false isNegtiveZero(-0 + (-0)) //ture isPositiveZero(+0 - (+0)) //ture isPositiveZero(+0 - (-0)) //ture isPositiveZero(-0 - (+0)) //false isNegtiveZero(-0 - (+0)) //ture isPositiveZero(-0 - (-0)) //ture總結
以上是生活随笔為你收集整理的JavaScript中正负零的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 切换、重定向、重选
- 下一篇: 自配料的误区,最好搭配净霉宝哦