Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since июль 2015 г..
Метод Math.log2() возвращает двоичный (по основанию 2) логарифм числа, то есть
∀x>0,Math.log2(x)=log2(x)=уникальныйyтакой, что2y=x\forall x > 0, \mathtt{\operatorname{Math.log2}(x)} = \log_2(x) = \text{уникальный} ; y ; \text{такой, что} ; 2^y = xЧисло.
Если значение x меньше 0, возвращаемое значение всегда будет равным NaN.
Поскольку метод log2() является статическим методом объекта Math, вы всегда должны использовать его как Math.log2(), а не пытаться вызывать метод на созданном экземпляре объекта Math (поскольку объект Math не является конструктором).
Этот метод может эмулироваться следующим способом:
| ECMAScript® 2027 Language Specification # sec-math.log2 |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 17 февр. 2025 г. by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.