On this page本页内容
$log¶New in version 3.2.版本3.2中的新功能。
Calculates the log of a number in the specified base and returns the result as a double.计算指定基数中某个数字的对数,并以双精度形式返回结果。
$log has the following syntax:语法如下所示:
The <number> expression can be any valid expression as long as it resolves to a non-negative number.<number>表达式可以是任何有效的表达式,只要它解析为非负数。
The <base> expression can be any valid expression as long as it resolves to a positive number greater than 1.<base>表达式可以是任何有效的表达式,只要它解析为大于1的正数。
For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
If either argument resolves to a value of 如果任一参数解析为null or refers to a field that is missing, $log returns null. null值或引用缺少的字段,$log返回null。If either argument resolves to 如果任一参数解析为NaN, $log returns NaN.NaN,$log返回NaN。
{ $log: [ 100, 10 ] } |
2 |
{ $log: [ 100, Math.E ] } Math.E is a JavaScript representation for e.Math.E是e的JavaScript表示形式。 |
4.605170185988092 |
A collection 集合examples contains the following documents:examples包含以下文档:
The following example uses log2 in its calculation to determine the number of bits required to represent the value of 下面的示例在计算中使用log2来确定表示positiveInt.positiveInt值所需的位数。
The operation returns the following results:操作返回以下结果: