Skip to content

Type instability in ldexp with Float32 arguments #88

@ptiede

Description

@ptiede

Hi,

This is a cross-post with JuliaDiff/ForwardDiff.jl#604.
The rule for ldexp(x,y) always returns a Float64 regardless of the type of the first argument x.
This is because the rule is given by

@define_diffrule Base.ldexp(x, y)  = :( exp2($y) ), :NaN

and since y is an Int exp2 by default return a Float64. @mcabbott pointed out that if we change the rule to

@define_diffrule Base.ldexp(x, y)  = :(  oftype(float($x), exp2($y)  ), :NaN

then we should maintain the Float32 type throughout the computation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions