# Promote big duals in ForwardDiff

**URL:** <https://discourse.julialang.org/t/promote-big-duals-in-forwarddiff/53126>\
**Category:** General Usage\
**Tags:** forwarddiff, bigfloat\
**Created:** [January 10, 2021, 10:30pm UTC](https://discourse.julialang.org/t/promote-big-duals-in-forwarddiff/53126 "2021-01-10T22:30:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xzackli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xzackli/32/38301_2.png) [@xzackli](https://discourse.julialang.org/u/xzackli)\
**Post date:** [January 10, 2021, 10:30pm UTC](https://discourse.julialang.org/t/promote-big-duals-in-forwarddiff/53126/1 "2021-01-10T22:30:31Z")

</div>

I’m computing some derivatives of functions where the interior temporarily enters the realm of BigFloat,

```julia
using ForwardDiff
g(x) = float(log(exp(x*1e6)))
ForwardDiff.derivative(g, 1.0)

```

```julia
NaN

```

In this example, the exponent is too large for float. One can promote a scalar which isn’t a dual, which surprisingly works.

```julia
using ForwardDiff
g(x) = float(log(exp(x*big(1e6))))
ForwardDiff.derivative(g, 1.0)

```

```julia
1.0e+06

```

Computing a derivative with respect to a BigFloat also works,

```julia
g2(x) = float(log(exp(x*1e6)))
ForwardDiff.derivative(g2, big(1.0))

```

```julia
1.0e+06

```

However, a naive approach where one attempts to promote a dual does not work.

```julia
g(x) = float(log(exp(big(x)*1e6)))
ForwardDiff.derivative(g, 1.0)

```

```julia
ERROR: LoadError: MethodError: no method matching big(::ForwardDiff.Dual{ForwardDiff.Tag{typeof(g),Float64},Float64,1})
Closest candidates are:
  big(::Type{Complex{T}}) where T<:Real at complex.jl:1018
  big(::Type{var"#s828"} where var"#s828"<:Integer) at gmp.jl:465
  big(::Type{var"#s828"} where var"#s828"<:Rational) at gmp.jl:466
  ...

```

A really naive definition would be to define

```julia
import Base: big
big(x::ForwardDiff.Dual{TG, T}) where {TG, T} = big(one(T)) * x

```

Since such promotion rules aren’t in ForwardDiff, I’m wondering if there are dangers associated with this latter approach?
