|
Prev | Next |
zdouble class acts like the double type
with the added property that zero times any value is zero.
This includes zero time nan
and zero times infinity.
In addition, zero divided by any value and any value times zero
are also zero.
zdouble z
zdouble z(x)
z1 op x
where
x
is a double or zdouble object
and
op
is =, +=, -=, *=
or /=-.
b = z op x
b = x op z
where
b
is a bool object,
z
is a zdouble object,
x
is a double or zdouble object, and
op
is ==, !=, <=, >=,
< or >.
z2 = z1 op x
z2 = x op z1
where
z1
,
z2
are zdouble objects,
x
is a double or zdouble object, and
op
is +, -, * or /.
z2 = fun(z1)
z3 = pow(z1, z2)
where
z1
,
z2
,
z3
are zdouble objects and
fun
is a unary_standard_math
function.
z2 = nan(z1)
returns 'not a number' when
z1
has type zdouble.
Note that this template function needs to be specialized because
zdouble(0.0) == zdouble(0.0) / zdouble(0.0)
result = flag * value_if_true + (1 - flag) * value_if_false
where
flag
is one for true and zero for false.
This representation does not work for double when the value
being multiplied by zero is +inf, -inf, or nan.
result = flag * value_if_true + (1 - flag) * value_if_false
This works fine except when there are
multiple levels of AD
; e.g.,
when using
AD< AD<double> >
.
In this case the corresponding AD function objects have type
ADFun< AD<double> >
.
When these AD function objects compute derivatives using
reverse
mode, the conditional expressions are represented use
zeros to multiply the expression that is not used.
Using
AD< AD<zdouble> >
instead of AD< AD<double> >
makes this representation work and fixes the problem.
zdouble satisfies all of the CppAD
base type requirements
.