Back to Influxdb

math.modf() function

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

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

math.modf() returns integer and fractional floating-point numbers that sum to f.

Both values have the same sign as f.

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

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

Parameters

f

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

Examples

Return the integer and float that sum to a value

js
import "math"

math.modf(f: 3.14)// {frac: 0.14000000000000012, int: 3}


Use math.modf in map

js
import "math"
import "sampledata"

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

            return {_time: r._time, int: result.int, 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

_timefracint
2021-01-01T00:00:00Z-0.18000000000000016-2
2021-01-01T00:00:10Z0.919999999999999910
2021-01-01T00:00:20Z0.349999999999999647
2021-01-01T00:00:30Z0.530000000000001117
2021-01-01T00:00:40Z0.2300000000000004315
2021-01-01T00:00:50Z0.42999999999999974
2021-01-01T00:00:00Z0.850000000000001419
2021-01-01T00:00:10Z0.96999999999999984
2021-01-01T00:00:20Z-0.75-3
2021-01-01T00:00:30Z0.769999999999999619
2021-01-01T00:00:40Z0.859999999999999413
2021-01-01T00:00:50Z0.86000000000000011

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