Back to Influxdb

math.log2() function

content/flux/v0/stdlib/math/log2.md

latest3.0 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/math/math.flux#L1493-L1493 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

math.log2() is a function returns the binary logarithm of x.

Function type signature
js
(x: float) => float

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

x

({{< req >}}) the value used in the operation.

Examples

Return the binary logarithm of a value

js
import "math"

math.log2(x: 3.14)// 1.6507645591169022


Use math.log2 in map

js
import "sampledata"
import "math"

sampledata.float()
    |> map(fn: (r) => ({r with _value: math.log2(x: r._value)}))

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time*tag_value
2021-01-01T00:00:00Zt1-2.18
2021-01-01T00:00:10Zt110.92
2021-01-01T00:00:20Zt17.35
2021-01-01T00:00:30Zt117.53
2021-01-01T00:00:40Zt115.23
2021-01-01T00:00:50Zt14.43
_time*tag_value
2021-01-01T00:00:00Zt219.85
2021-01-01T00:00:10Zt24.97
2021-01-01T00:00:20Zt2-3.75
2021-01-01T00:00:30Zt219.77
2021-01-01T00:00:40Zt213.86
2021-01-01T00:00:50Zt21.86

Output data

_time_value*tag
2021-01-01T00:00:00ZNaNt1
2021-01-01T00:00:10Z3.4489009511451276t1
2021-01-01T00:00:20Z2.877744249949002t1
2021-01-01T00:00:30Z4.131754090984813t1
2021-01-01T00:00:40Z3.9288440367125674t1
2021-01-01T00:00:50Z2.1473066987802936t1
_time_value*tag
2021-01-01T00:00:00Z4.3110671022555955t2
2021-01-01T00:00:10Z2.3132458517875616t2
2021-01-01T00:00:20ZNaNt2
2021-01-01T00:00:30Z4.305240965954483t2
2021-01-01T00:00:40Z3.792855352362489t2
2021-01-01T00:00:50Z0.8953026213333067t2

{{% /expand %}} {{< /expand-wrapper >}}