﻿---
title: ES|QL COPY_SIGN function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/3016/reference/query-languages/esql/functions-operators/math-functions/copy_sign
products:
  - Elasticsearch
---

# ES|QL COPY_SIGN function
<applies-to>
  - Elastic Stack: Generally available since 9.1
</applies-to>


## Syntax

![Embedded](https://www.elastic.co/elastic/docs-builder/docs/3016/reference/query-languages/esql/images/functions/copy_sign.svg)


## Parameters

<definitions>
  <definition term="magnitude">
    The expression providing the magnitude of the result. Must be a numeric type.
  </definition>
  <definition term="sign">
    The expression providing the sign of the result. Must be a numeric type.
  </definition>
</definitions>


## Description

Returns a value with the magnitude of the first argument and the sign of the second argument. This function is similar to Java's Math.copySign(double magnitude, double sign) which is similar to `copysign` from [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754).

## Supported types


| magnitude | sign    | result  |
|-----------|---------|---------|
| double    | double  | double  |
| double    | integer | double  |
| double    | long    | double  |
| integer   | double  | integer |
| integer   | integer | integer |
| integer   | long    | integer |
| long      | double  | long    |
| long      | integer | long    |
| long      | long    | long    |


## Example

```esql
FROM employees
| EVAL cs1 = COPY_SIGN(salary, LEAST(salary_change))
```


| emp_no:integer | salary:integer | salary_change:double | cs1:integer |
|----------------|----------------|----------------------|-------------|
| 10001          | 57305          | 1.19                 | 57305       |
| 10002          | 56371          | [-7.23, 11.17]       | -56371      |
| 10003          | 61805          | [12.82, 14.68]       | 61805       |