Skip to content

Float32/16 raised to an integer's typemin throws a DomainError #57464

@mbarbar

Description

@mbarbar

It shouldn't throw because there is generally no issue raising a Float to a negative power.

julia> x = Float32(1.1)
1.1f0

julia> y = typemin(Int64)
-9223372036854775808

julia> x ^ y
ERROR: DomainError with -9223372036854775808:
Cannot raise an integer x to a negative power -9223372036854775808.
Convert input to float.
Stacktrace:
 [1] throw_domerr_powbysq(::Float64, p::Int64)
   @ Base ./intfuncs.jl:262
 [2] power_by_squaring(x_::Float64, p::Int64)
   @ Base ./intfuncs.jl:286
 [3] ^(x::Float32, n::Int64)
   @ Base.Math ./math.jl:1280
 [4] top-level scope
   @ REPL[66]:1

julia> x ^ (y+1)
0.0f0

At some point there's a -exponent but -typemin(Int) == typemin(Int).

I've also opened #57463 but this goes through a different path (and anyway produce an incorrect result rather than an exception).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviormathsMathematical functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions