---
title: math.copysign() function
description: math.copysign() returns a value with the magnitude x and the sign of y.
url: https://docs.influxdata.com/flux/v0/stdlib/math/copysign/
estimated_tokens: 445
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/stdlib/math/copysign/
date: '2024-04-08T16:01:02-06:00'
lastmod: '2024-04-08T16:01:02-06:00'
---

* Flux 0.22.0+

InfluxDB support

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

##### Function type signature

```js
(x: float, y: float) => float
```

For more information, see [Function type signatures](/flux/v0/function-type-signatures/).

## Parameters

### x

(Required)
Magnitude to use in the operation.

### y

(Required)
Sign to use in the operation.

## Examples

* [Return the copysign of two columns](#return-the-copysign-of-two-columns)
* [Use math.copysign in map](#use-mathcopysign-in-map)

### 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)}))
```

[](#view-example-input-and-output)

View example input and output

#### Input data

|       \_time       | x |  y  |
|--------------------|---|-----|
|2021-01-01T00:00:00Z|1.2| 3.9 |
|2021-01-01T01:00:00Z|2.4|\-4.2|
|2021-01-01T02:00:00Z|3.6| 5.3 |
|2021-01-01T03:00:00Z|4.8|\-6.8|
|2021-01-01T04:00:00Z|5.1| 7.5 |

#### Output data

|       \_time       |\_value|
|--------------------|-------|
|2021-01-01T00:00:00Z|  1.2  |
|2021-01-01T01:00:00Z| \-2.4 |
|2021-01-01T02:00:00Z|  3.6  |
|2021-01-01T03:00:00Z| \-4.8 |
|2021-01-01T04:00:00Z|  5.1  |
| _time | x | y |
| --- | --- | --- |
| _time | x | y |
| 2021-01-01T00:00:00Z | 1.2 | 3.9 |
| 2021-01-01T01:00:00Z | 2.4 | -4.2 |
| 2021-01-01T02:00:00Z | 3.6 | 5.3 |
| 2021-01-01T03:00:00Z | 4.8 | -6.8 |
| 2021-01-01T04:00:00Z | 5.1 | 7.5 |

| _time | _value |
| --- | --- |
| _time | _value |
| 2021-01-01T00:00:00Z | 1.2 |
| 2021-01-01T01:00:00Z | -2.4 |
| 2021-01-01T02:00:00Z | 3.6 |
| 2021-01-01T03:00:00Z | -4.8 |
| 2021-01-01T04:00:00Z | 5.1 |
