docs-v2/content/flux/v0/stdlib/math/ldexp.md

3.3 KiB

title description menu weight
math.ldexp() function `math.ldexp()` is the inverse of `math.frexp()`. It returns `frac x 2**exp`.
flux_v0_ref
name parent identifier
math.ldexp math math/ldexp
101

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

Function type signature
(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

import "math"

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


Use math.ldexp in map

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 _time exp frac
t1 2021-01-01T00:00:00Z 2 -0.545
t1 2021-01-01T00:00:10Z 4 0.6825
t1 2021-01-01T00:00:20Z 3 0.91875
t1 2021-01-01T00:00:30Z 5 0.5478125
t1 2021-01-01T00:00:40Z 4 0.951875
t1 2021-01-01T00:00:50Z 3 0.55375
*tag _time exp frac
t2 2021-01-01T00:00:00Z 5 0.6203125
t2 2021-01-01T00:00:10Z 3 0.62125
t2 2021-01-01T00:00:20Z 2 -0.9375
t2 2021-01-01T00:00:30Z 5 0.6178125
t2 2021-01-01T00:00:40Z 4 0.86625
t2 2021-01-01T00:00:50Z 1 0.93

Output data

_time _value *tag
2021-01-01T00:00:00Z -2.18 t1
2021-01-01T00:00:10Z 10.92 t1
2021-01-01T00:00:20Z 7.35 t1
2021-01-01T00:00:30Z 17.53 t1
2021-01-01T00:00:40Z 15.23 t1
2021-01-01T00:00:50Z 4.43 t1
_time _value *tag
2021-01-01T00:00:00Z 19.85 t2
2021-01-01T00:00:10Z 4.97 t2
2021-01-01T00:00:20Z -3.75 t2
2021-01-01T00:00:30Z 19.77 t2
2021-01-01T00:00:40Z 13.86 t2
2021-01-01T00:00:50Z 1.86 t2

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