Back to Influxdb

math.frexp() function

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

latest3.4 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#L957-L957 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

math.frexp() breaks f into a normalized fraction and an integral part of two.

It returns frac and exp satisfying f == frac x 2**exp, with the absolute value of frac in the interval [1/2, 1).

Function type signature
js
(f: float) => {frac: float, exp: int}

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

Parameters

f

({{< req >}}) Value to operate on.

Examples

Return the normalize fraction and integral of a value

js
import "math"

math.frexp(f: 22.0)// {exp: 5, frac: 0.6875}


Use math.frexp in map

js
import "sampledata"
import "math"

sampledata.float()
    |> map(
        fn: (r) => {
            result = math.frexp(f: r._value)

            return {r with exp: result.exp, frac: result.frac}
        },
    )

{{< 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_valueexpfrac*tag
2021-01-01T00:00:00Z-2.182-0.545t1
2021-01-01T00:00:10Z10.9240.6825t1
2021-01-01T00:00:20Z7.3530.91875t1
2021-01-01T00:00:30Z17.5350.5478125t1
2021-01-01T00:00:40Z15.2340.951875t1
2021-01-01T00:00:50Z4.4330.55375t1
_time_valueexpfrac*tag
2021-01-01T00:00:00Z19.8550.6203125t2
2021-01-01T00:00:10Z4.9730.62125t2
2021-01-01T00:00:20Z-3.752-0.9375t2
2021-01-01T00:00:30Z19.7750.6178125t2
2021-01-01T00:00:40Z13.8640.86625t2
2021-01-01T00:00:50Z1.8610.93t2

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