Back to Influxdb

math.ldexp() function

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

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

math.ldexp() is the inverse of math.frexp(). It returns frac x 2**exp.

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

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

Parameters

frac

({{< req >}}) Fraction to use in the operation.

exp

({{< req >}}) Exponent to use in the operation.

Examples

Return the inverse of math.frexp

js
import "math"

math.ldexp(frac: 0.5, exp: 6)// 32.0


Use math.ldexp in map

js
import "math"

data
    |> map(fn: (r) => ({_time: r._time, tag: r.tag, _value: math.ldexp(frac: r.frac, exp: r.exp)}))

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

Input data

*tag_timeexpfrac
t12021-01-01T00:00:00Z2-0.545
t12021-01-01T00:00:10Z40.6825
t12021-01-01T00:00:20Z30.91875
t12021-01-01T00:00:30Z50.5478125
t12021-01-01T00:00:40Z40.951875
t12021-01-01T00:00:50Z30.55375
*tag_timeexpfrac
t22021-01-01T00:00:00Z50.6203125
t22021-01-01T00:00:10Z30.62125
t22021-01-01T00:00:20Z2-0.9375
t22021-01-01T00:00:30Z50.6178125
t22021-01-01T00:00:40Z40.86625
t22021-01-01T00:00:50Z10.93

Output data

_time_value*tag
2021-01-01T00:00:00Z-2.18t1
2021-01-01T00:00:10Z10.92t1
2021-01-01T00:00:20Z7.35t1
2021-01-01T00:00:30Z17.53t1
2021-01-01T00:00:40Z15.23t1
2021-01-01T00:00:50Z4.43t1
_time_value*tag
2021-01-01T00:00:00Z19.85t2
2021-01-01T00:00:10Z4.97t2
2021-01-01T00:00:20Z-3.75t2
2021-01-01T00:00:30Z19.77t2
2021-01-01T00:00:40Z13.86t2
2021-01-01T00:00:50Z1.86t2

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