copysign

  1. R copysign(R to, X from)
  2. R copysign(X to, R from)
    @trusted pure nothrow @nogc
    R
    copysign
    (
    R
    X
    )
    (
    X to
    ,)

Parameters

to X

the numeric value to use

from R

the sign value to use

Return Value

Type: R

a value composed of to with from's sign bit.

Examples

assert(copysign(1.0, 1.0) == 1.0);
assert(copysign(1.0, -0.0) == -1.0);
assert(copysign(1UL, -1.0) == -1.0);
assert(copysign(-1.0, -1.0) == -1.0);

assert(copysign(real.infinity, -1.0) == -real.infinity);
assert(copysign(real.nan, 1.0) is real.nan);
assert(copysign(-real.nan, 1.0) is real.nan);
assert(copysign(real.nan, -1.0) is -real.nan);

Meta