Skip to content

Euclidean breaks when Int overflow occurs #269

Open
@schlichtanders

Description

@schlichtanders
julia> Distances.evaluate(Euclidean(), Int16(-1360), Int16(-136))
ERROR: DomainError with -9152.0:
sqrt was called with a negative real argument but will only return a complex result if called with a complex argument. Try sqrt(Complex(x)).
Stacktrace:
 [1] throw_complex_domainerror(f::Symbol, x::Float64)
   @ Base.Math ./math.jl:33
 [2] sqrt
   @ ./math.jl:608 [inlined]
 [3] sqrt
   @ ./math.jl:1531 [inlined]
 [4] eval_end
   @ ~/.julia/packages/Distances/mlz7p/src/metrics.jl:336 [inlined]
 [5] _evaluate
   @ ~/.julia/packages/Distances/mlz7p/src/metrics.jl:314 [inlined]
 [6] Euclidean
   @ ~/.julia/packages/Distances/mlz7p/src/metrics.jl:331 [inlined]
 [7] evaluate(dist::Euclidean, a::Int16, b::Int16)
   @ Distances ~/.julia/packages/Distances/mlz7p/src/generic.jl:47
 [8] top-level scope
   @ REPL[32]:1

julia> Distances.eval_op(Euclidean(), Int16(-1360), Int16(-136))
-9152

Would be nice if instead of an error, the typemax is returned, ideally with a check whether the operations are incurring an overflow

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