Skip to content

rational.jl: rationalize NaN #26823

Closed
Closed
@ederag

Description

Reading the documentation about conversion and promotion of 0.6.2, the isnan line looked weird:

function convert(::Type{Rational{T}}, x::AbstractFloat, tol::Real) where T<:Integer
    if isnan(x); return zero(T)//zero(T); end

The issue is multiple:

  • in the actual source convert has been changed to rationalize. The doc could be updated, for clarity.
  • Trying that in julia 0.6.2 yields an error message that could be puzzling before looking at the source.
julia> rationalize(Int64, NaN, 1e-16)
ERROR: ArgumentError: invalid rational: zero(Int64)//zero(Int64)
Stacktrace:
 [1] Rational{Int64}(::Int64, ::Int64) at ./rational.jl:13
 [2] rationalize(::Type{Int64}, ::Float64, ::Float64) at ./rational.jl:131

What about replacing zero(T)//zero(T) with something like throw(ArgumentError("received NaN, not allowed for integer-related types") ?

Here is the corresponding line in the repo:

isnan(x) && return zero(T)//zero(T)

This is not #25702.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    rationalsThe Rational type and values thereof

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions