The OpenD Programming Language

copysign

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

Parameters

to R

the numeric value to use

from X

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