dual

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

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

Parameters

R

(template parameter) type of real part of dual number

re
Type: 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

1 auto a = dual(1.0);
2 static assert(is(typeof(a) == Dual!double));
3 assert(a.re == 1.0);
4 assert(a.du == 0.0);
5 
6 auto b = dual(2.0L);
7 static assert(is(typeof(b) == Dual!real));
8 assert(b.re == 2.0L);
9 assert(b.du == 0.0L);
10 
11 auto c = dual(1.0, 2.0);
12 static assert(is(typeof(c) == Dual!double));
13 assert(c.re == 1.0);
14 assert(c.du == 2.0);
15 
16 auto d = dual(3.0, 4.0L);
17 static assert(is(typeof(d) == Dual!real));
18 assert(d.re == 3.0);
19 assert(d.du == 4.0L);
20 
21 auto e = dual(1);
22 static assert(is(typeof(e) == Dual!double));
23 assert(e.re == 1);
24 assert(e.du == 0);
25 
26 auto f = dual(1L, 2);
27 static assert(is(typeof(f) == Dual!double));
28 assert(f.re == 1L);
29 assert(f.du == 2);
30 
31 auto g = dual(3, 4.0L);
32 static assert(is(typeof(g) == Dual!real));
33 assert(g.re == 3);
34 assert(g.du == 4.0L);

Meta