parse(<type>,"Inf")

I’m reading in some environment variables and sometimes I need to get Inf.

Obviously Inf is not an Int, but can I do something like:

arc_nu = parse(Int,ENV["ARCNU"]) # where ENV["ARCNU"] = "Inf"
@test isinf(arc_nu) == true

parse(Float64, "Inf")

or

x = ENV["ARCNU"]; x == "Inf" ? Inf : parse(Int, x)

or

x = ENV["ARCNU"]; x == "Inf" ? typemax(Int) : parse(Int, x)

1 Like

thanks, the ternary actually works much better for me here

1 Like