Back to Influxdb

math.copysign() function

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

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

math.copysign() returns a value with the magnitude x and the sign of y.

Function type signature
js
(x: float, y: float) => float

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

Parameters

x

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

y

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

Examples

Return the copysign of two columns

js
import "math"

math.copysign(x: 1.0, y: 2.0)

Use math.copysign in map

js
import "math"

data
    |> map(fn: (r) => ({_time: r._time, _value: math.copysign(x: r.x, y: r.y)}))

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

Input data

_timexy
2021-01-01T00:00:00Z1.23.9
2021-01-01T01:00:00Z2.4-4.2
2021-01-01T02:00:00Z3.65.3
2021-01-01T03:00:00Z4.8-6.8
2021-01-01T04:00:00Z5.17.5

Output data

_time_value
2021-01-01T00:00:00Z1.2
2021-01-01T01:00:00Z-2.4
2021-01-01T02:00:00Z3.6
2021-01-01T03:00:00Z-4.8
2021-01-01T04:00:00Z5.1

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