Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript (0!)_Javascript_Math_Browser_Cross Browser - Fatal编程技术网

Javascript (0!)

Javascript (0!),javascript,math,browser,cross-browser,Javascript,Math,Browser,Cross Browser,简短的回答是“视情况而定。” 如果您在任何位置使用位运算符(或如果您指的是数组的长度),则范围为: 未签名:0…(-1>>0) 签名:(-1>>1)-1).(-1>>1) (按位运算符和数组的最大长度限制为32位整数。) 如果不使用位运算符或不使用数组长度: 签名:(-Math.pow(2,53))…(+Math.pow(2,53)) 这些限制是由“数字”类型的内部表示施加的,该类型通常对应于IEEE 754双精度浮点表示。(注意,与典型的有符号整数不同,由于内部表示的特性,负极限的大小与正极限

简短的回答是“视情况而定。”

如果您在任何位置使用位运算符(或如果您指的是数组的长度),则范围为:

未签名:
0…(-1>>0)

签名:
(-1>>1)-1).(-1>>1)

(按位运算符和数组的最大长度限制为32位整数。)

如果不使用位运算符或不使用数组长度:

签名:
(-Math.pow(2,53))…(+Math.pow(2,53))

这些限制是由“数字”类型的内部表示施加的,该类型通常对应于IEEE 754双精度浮点表示。(注意,与典型的有符号整数不同,由于内部表示的特性,负极限的大小与正极限的大小相同,实际上包含负0!)

为了安全起见 推理 我想我会很聪明,用更务实的方法找到
x+1===x
的值

我的机器每秒只能数1000万左右。。。因此,我将在28.56年后发布最终答案

如果你不能等那么久,我敢打赌

  • 你的大部分循环都不会运行28.56年
  • 9007199254740992===Math.pow(2,53)+1
    足以证明
  • 您应该坚持使用
    4294967295
    ,即
    Math.pow(2,32)-1
    ,以避免位移位的预期问题
查找
x+1===x

(function () {
  "use strict";

  var x = 0
    , start = new Date().valueOf()
    ;

  while (x + 1 != x) {
    if (!(x % 10000000)) {
      console.log(x);
    }

    x += 1
  }

  console.log(x, new Date().valueOf() - start);
}());
为了安全 推理 我想我会很聪明,用更务实的方法找到
x+1===x
的值

我的机器每秒只能数1000万左右。。。因此,我将在28.56年后发布最终答案

如果你不能等那么久,我敢打赌

  • 你的大部分循环都不会运行28.56年
  • 9007199254740992===Math.pow(2,53)+1
    足以证明
  • 您应该坚持使用
    4294967295
    ,即
    Math.pow(2,32)-1
    ,以避免位移位的预期问题
查找
x+1===x

(function () {
  "use strict";

  var x = 0
    , start = new Date().valueOf()
    ;

  while (x + 1 != x) {
    if (!(x % 10000000)) {
      console.log(x);
    }

    x += 1
  }

  console.log(x, new Date().valueOf() - start);
}());

在Google Chrome内置javascript中,在数字被称为无穷大之前,您可以转到大约2^1024。

在Google Chrome内置javascript中,在数字被称为无穷大之前,您可以转到大约2^1024。

在javascript中,有一个数字被称为
无穷大

示例:

(Infinity>100)
=> true

// Also worth noting
Infinity - 1 == Infinity
=> true

Math.pow(2,1024) === Infinity
=> true

这可能足以回答与此主题相关的一些问题。

在JavaScript中,有一个数字称为
无限

示例:

(Infinity>100)
=> true

// Also worth noting
Infinity - 1 == Infinity
=> true

Math.pow(2,1024) === Infinity
=> true

这可能足以回答有关此主题的一些问题。

要用于位运算的任何内容必须介于0x8000000(-2147483648或-2^31)和0x7fffffff(2147483647或2^31-1)之间


控制台将告诉您0x8000000等于+2147483648,但0x8000000&0x8000000等于-2147483648。

要用于位运算的任何内容都必须介于0x8000000(-2147483648或-2^31)和0x7FFFFFFFFF(2147483647或2^31-1)之间

控制台将告诉您0x80000000等于+2147483648,但0x80000000和0x80000000等于-2147483648。

正确地将连续JavaScript整数谱表示为-90071992547409929007199254740992(抱歉9007199254740993,您可能认为您是9007199254740993,但您错了! 下面或里面的演示)

console.log(9007199254740993);
正确地将连续JavaScript整数谱表示为-90071992547409929007199254740992包括在内(对不起,9007199254740993,您可能认为您是9007199254740993,但您错了! 下面或里面的演示)


console.log(9007199254740993);
Node.js和Google Chrome似乎都在使用1024位浮点值,因此:

Number.MAX_VALUE = 1.7976931348623157e+308

Node.js和Google Chrome似乎都使用1024位浮点值,因此:

Number.MAX_VALUE = 1.7976931348623157e+308

其他人可能已经给出了一般性的答案,但我认为最好给出一种快速确定答案的方法:

for (var x = 2; x + 1 !== x; x *= 2);
console.log(x);
在Chrome 30中,在不到一毫秒的时间内,我得到了9007199254740992


它将测试2的幂,以确定当“添加”1时,哪一个等于他自己。

其他人可能已经给出了一般性的答案,但我认为最好给出一种快速确定它的方法:

for (var x = 2; x + 1 !== x; x *= 2);
console.log(x);
在Chrome 30中,在不到一毫秒的时间内,我得到了9007199254740992

它将测试2的幂,以确定当“添加”1时,哪一个等于他自己。

ECMAScript 6:

Number.MAX_SAFE_INTEGER = Math.pow(2, 53)-1;
Number.MIN_SAFE_INTEGER = -Number.MAX_SAFE_INTEGER;
ECMAScript 6:

Number.MAX_SAFE_INTEGER = Math.pow(2, 53)-1;
Number.MIN_SAFE_INTEGER = -Number.MAX_SAFE_INTEGER;
我是这样写的:

var max_int = 0x20000000000000;
var min_int = -0x20000000000000;
(max_int + 1) === 0x20000000000000;  //true
(max_int - 1) < 0x20000000000000;    //true
我是这样写的:

var max_int = 0x20000000000000;
var min_int = -0x20000000000000;
(max_int + 1) === 0x20000000000000;  //true
(max_int - 1) < 0x20000000000000;    //true
斯卡托·沃特斯:

要用于位运算的任何内容都必须介于 0x8000000(-2147483648或-2^31)和0x7fffffff(2147483647或2^31- 1)

控制台将告诉您0x8000000等于+2147483648,但是 0x8000000和0x8000000等于-2147483648

十六进制小数是无符号正值,因此0x8000000=2147483648-这在数学上是正确的。如果要使其成为有符号值,则必须右移:0x8000000>>0=-2147483648。您可以写入1Scato wrotes:

要用于位运算的任何内容都必须介于 0x8000000(-2147483648或-2^31)和0x7fffffff(2147483647或2^31- 1)

控制台将告诉您0x8000000等于+2147483648,但是 0x8000000和0x8000000等于-2147483648


十六进制小数是无符号的正值,所以0x8000000=2147483648-这在数学上是正确的。如果你想使它成为有符号的值,你必须右移:0x8000000>>0=-2147483648。你可以写1许多早期的答案显示
900719925474992==900719925474992+1
大于9,
var max_int = 0x20000000000000;
var min_int = -0x20000000000000;
(max_int + 1) === 0x20000000000000;  //true
(max_int - 1) < 0x20000000000000;    //true
var max_int32 =  0x80000000;
var min_int32 = -0x80000000;
input: 9007199254740992 + 1  output: 9007199254740992  // expected: 9007199254740993
input: 9007199254740992 + 2  output: 9007199254740994  // expected: 9007199254740994
input: 9007199254740992 + 3  output: 9007199254740996  // expected: 9007199254740995
input: 9007199254740992 + 4  output: 9007199254740996  // expected: 9007199254740996
  1 . 0000 ---- 0000  *  2^52            =>  1  0000 ---- 0000.  
     |-- 52 bits --|    |exponent part|        |-- 52 bits --|
  1 . 0000 ---- 0000  *  2^52  =>  1  0000 ---- 0000.  
                       (+1)
  1 . 0000 ---- 0001  *  2^52  =>  1  0000 ---- 0001.  
                       (+1)
  1 . 0000 ---- 0010  *  2^52  =>  1  0000 ---- 0010.  
                       (+1)
                        . 
                        .
                        .
  1 . 1111 ---- 1111  *  2^52  =>  1  1111 ---- 1111. 
  ┏━━▶ This bit is implicit and persistent.
  ┃        
  1 . 1111 ---- 1111  *  2^52      =>  1  1111 ---- 1111. 
     |-- 52 bits --|                     |-- 52 bits --|

                          (+1)

  1 . 0000 ---- 0000  *  2^52 * 2  =>  1  0000 ---- 0000. * 2  
     |-- 52 bits --|                     |-- 52 bits --|
                                      (By consuming the 2^52, radix
                                       point has no way to go, but
                                       there is still one 2 left in
                                       exponent part)
  =>  1 . 0000 ---- 0000  *  2^53 
         |-- 52 bits --| 
                            (consume 2^52 to move radix point to the end)
  1 . 0000 ---- 0001  *  2^53  =>  1  0000 ---- 0001.  *  2
     |-- 52 bits --|                 |-- 52 bits --|
input: 18014398509481984 + 1  output: 18014398509481984  // expected: 18014398509481985
input: 18014398509481984 + 2  output: 18014398509481984  // expected: 18014398509481986
input: 18014398509481984 + 3  output: 18014398509481984  // expected: 18014398509481987
input: 18014398509481984 + 4  output: 18014398509481988  // expected: 18014398509481988
 1 . 0000 ---- 0001  *  2^51  =>  1 0000 ---- 000.1
     |-- 52 bits --|                |-- 52 bits  --|
input: 4503599627370495.5   output: 4503599627370495.5  
input: 4503599627370495.75  output: 4503599627370495.5  
            
input: 2251799813685246.75   output: 2251799813685246.8  // expected: 2251799813685246.75 
input: 2251799813685246.25   output: 2251799813685246.2  // expected: 2251799813685246.25 
input: 2251799813685246.5    output: 2251799813685246.5
/**
   Please note that if you try this yourself and, say, log 
   these numbers to the console, they will get rounded. JavaScript
   rounds if the number of digits exceed 17. The value 
   is internally held correctly:
*/
            
input: 2251799813685246.25.toString(2) 
output: "111111111111111111111111111111111111111111111111110.01"
input: 2251799813685246.75.toString(2) 
output: "111111111111111111111111111111111111111111111111110.11"
input: 2251799813685246.78.toString(2)   
output: "111111111111111111111111111111111111111111111111110.11"
var a = 123456789012345678901012345678901n;
console.log(BigInt("1".padEnd(100000,"0")) + 1n)