Skip to content
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

-2の31乗とはなにか #1313

Closed
yumetodo opened this issue May 9, 2021 · 3 comments · Fixed by #1315
Closed

-2の31乗とはなにか #1313

yumetodo opened this issue May 9, 2021 · 3 comments · Fixed by #1315

Comments

@yumetodo
Copy link
Contributor

yumetodo commented May 9, 2021

該当ページ

https://github.com/asciidwango/js-primer/tree/master/source/basic/operator

説明

#1312 にコメントするのが遅れたのですが、

そのため符号付き32ビット整数で表現できる数値の範囲は-2の31乗(1111_1111_1111_1111_1111_1111_1111_1111)から2の31乗(0111_1111_1111_1111_1111_1111_1111_1111 )までとなります。

-2の31乗というのが、(-2)^31-(2^31)で曖昧な表現になっているように思います。

@azu azu added the Type: Bug label May 9, 2021
@azu
Copy link
Collaborator

azu commented May 9, 2021

ありがとうございます。たしかにおかしいですね。

  • -(2の31乗)
  • -(2^31)

後者のほうがわかりやすいのですが、^ を文章中で使ってないんですよね。
何かいい表現方法が必要ですね。

±2の31乗の範囲 とかはどうなんでしょう。

@yumetodo
Copy link
Contributor Author

yumetodo commented May 9, 2021

そういえばC++だと

#include <limits>
#include <cstdint>
using limit = std::numeric_limits<std::int32_t>;
static_assert(limit::min() + 1 == -limit::max());
int main()
{}

という環境もあるのですが、Javascriptはどうなのでしょう。

@azu
Copy link
Collaborator

azu commented May 9, 2021

The abstract operation ToInt32 takes argument argument. It converts argument to one of integral Number values in the range 𝔽(-231) through 𝔽(231 - 1), inclusive.
https://tc39.es/ecma262/#sec-toint32

みたいですね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants