Back to Influxdb

math.sincos() function

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

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

math.sincos() returns the values of math.sin(x:x) and math.cos(x:x).

Function type signature
js
(x: float) => {sin: float, cos: float}

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

Parameters

x

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

Examples

Return the sine and cosine of a value

js
import "math"

math.sincos(x: 1.23)// {cos: 0.3342377271245026, sin: 0.9424888019316975}


Use math.sincos in map

js
import "math"
import "sampledata"

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

            return {_time: r._time, tag: r._tag, sin: result.sin, cos: result.cos}
        },
    )

{{< 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

_timecossin
2021-01-01T00:00:00Z-0.5722145708524368-0.8201039476213742
2021-01-01T00:00:10Z-0.07550236802260023-0.9971456224759652
2021-01-01T00:00:20Z0.48291594165593790.8756667135928823
2021-01-01T00:00:30Z0.248605612678472-0.9686047952311415
2021-01-01T00:00:40Z-0.8879336028264720.4599716480084409
2021-01-01T00:00:50Z-0.2786508003590546-0.9603924882355435
2021-01-01T00:00:00Z0.53992857346496750.8417108384451784
2021-01-01T00:00:10Z0.25477113377824295-0.9670013802437661
2021-01-01T00:00:20Z-0.82055935733956060.5715613187423438
2021-01-01T00:00:30Z0.60546678737630240.7958705732618963
2021-01-01T00:00:40Z0.27363181655016850.9618345122584524
2021-01-01T00:00:50Z-0.285189059245020860.9584712830789142

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