math.copysign

Full name
math.copysign
Library
math
Syntax

math.copysign(m, n)

Description

The math.copysign function takes two numbers as arguments, m and n, and returns the absolute value of m with the sign of n.

Both m and n must be whole or real numbers, not complex numbers.

Parameters
  • m: number whose absolute value is to be returned.
  • n: number whose sign is to be returned.
Result

The result of the math.copysign function is a real number.

Examples

Several usage examples are shown below:

math.copysign(2, 3)

2.0

Note that the result is a real number even though the function's arguments are integers.

math.copysign(2, -3)

-2.0

math.copysign(-2.5, 3.5)

2.5

math.copysign(-2.5, -3.5)

-2.5

Submitted by admin on Wed, 01/20/2021 - 10:49