dual

Helper function that returns a dual number with the specified real and dual parts.

  1. auto dual(R re)
    @safe pure nothrow @nogc
    dual
    (
    R
    )
    (
    const R re
    )
    if (
    is(R : double)
    )
  2. auto dual(R re, D du)

Parameters

R

(template parameter) type of real part of dual number

re R

real part of complex number to be constructed

Return Value

Type: auto

Dual instance with real and dual parts set to the values provided as input. If neither re nor du are floating-point numbers, the return type will be Dual!double. Otherwise, the return type is deduced using std.traits.CommonType!(R, D).

Examples

auto a = dual(1.0);
static assert(is(typeof(a) == Dual!double));
assert(a.re == 1.0);
assert(a.du == 0.0);

auto b = dual(2.0L);
static assert(is(typeof(b) == Dual!real));
assert(b.re == 2.0L);
assert(b.du == 0.0L);

auto c = dual(1.0, 2.0);
static assert(is(typeof(c) == Dual!double));
assert(c.re == 1.0);
assert(c.du == 2.0);

auto d = dual(3.0, 4.0L);
static assert(is(typeof(d) == Dual!real));
assert(d.re == 3.0);
assert(d.du == 4.0L);

auto e = dual(1);
static assert(is(typeof(e) == Dual!double));
assert(e.re == 1);
assert(e.du == 0);

auto f = dual(1L, 2);
static assert(is(typeof(f) == Dual!double));
assert(f.re == 1L);
assert(f.du == 2);

auto g = dual(3, 4.0L);
static assert(is(typeof(g) == Dual!real));
assert(g.re == 3);
assert(g.du == 4.0L);

Meta