-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tryparse: parse string to Nullable #9487
Conversation
Just a thought why not |
Yes, |
Introducing the EDIT: fix types by adding |
@nalimilan That seems like a massive improvement in API. Seems like |
+1 for the API @nalimilan. |
@nalimilan Not sure why the AppVeyor build is failing though. Seems spurious, but it failed even after re-running the build. |
Or to avoid the conflict in meanings with the current |
@tanmaykm The AppVeyor failure doesn't sound so spurious, as the failure happens in |
The AppVeyor logs report:
whereas
Seems like some sort of corruption. |
sadly, that probably is due to #7906 |
bump. maybe we can merge this now? |
About api:
and
to make the distinction of whether a non-Int input should be allowed and returned add a null result. The latter call looks to like that it would look for a text representation of a (nullable) Int or null, and throw an error if neither was found. |
Will rebase and test again. |
@toivoh good point. We could have |
base = convert(T,base) | ||
m::T = div(typemax(T)-base+1,base) | ||
n::T = 0 | ||
while n <= m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid duplicating all of this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will be removing the duplication. Will pass the error string back through an optional ArgumentError
parameter so that only methods that throw would incur the overhead of creating it.
77a30d0
to
30665d6
Compare
Help! Any clues as to why this build is failing? https://travis-ci.org/JuliaLang/julia/builds/54050279 |
Usually this kind of error means that a compile-time function call relies on a type that's defined in a file that's included later in the bootstrap process. Here, it looks like parsing the literal array at Line 6 in 5b6468a
parseint which involves BigInt in one way or another. But I have a hard time understanding why this would only happen on 32-bit, and how your changes may have triggered this.
|
2931312
to
9441d5d
Compare
Thanks @nalimilan, I was able to reorder a portion of |
This now exports the
And:
This should fix #10498 as well. I shall rebase and add documentation if this looks fine. Should the |
Unless the |
|
@@ -180,6 +180,27 @@ big(n::Integer) = convert(BigInt,n) | |||
big(x::FloatingPoint) = convert(BigFloat,x) | |||
big(q::Rational) = big(num(q))//big(den(q)) | |||
|
|||
const _fact_table128 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you should put these lines here. This file contains almost exclusively includes. Have you tried simply moving include("combinatorics.jl")
below the BigInt section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are cross dependencies that break if the entire file is shifted. These were the only UInt128
dependent code that was there. I thought of putting these in an int128funcs.jl
file, but this seemed too small to go into a separate file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to come up with something else. Having a factorial table in sysimg.jl is bananas. What depends on combinatorics.jl? I thought almost nothing would depend on this; it's all extra library functions that we've discussed removing from Base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parsing UInt128
literals seems to require BigInt
in 32 bit environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like gmp.jl depends on factorial and binomial. The simple generic definitions of those can be moved to intfuncs.jl. That should solve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be fine if I move the binomial
and factorial
from gmp.jl
and mpfr.jl
into combinatorics.jl
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. So should they be moved to intfuncs.jl
or combinatorics.jl
since it already has the other variants?
I think I liked better Are there any other cases where a function should come in two versions, one returning a |
521fabe
to
a48582a
Compare
Introduces the tryparse method: - tryparse{T<:Integer}(::Type{T<:Integer},s::AbstractString) - tryparse(::Type{Float..},s::AbstractString) - a few variants of the above And: - tryparse(Float.., ...) call the corresponding C functions jl_try_strtof, jl_try_substrtof, jl_try_strtod and jl_try_substrtod. - The parseint, parsefloat, float64_isvalid and float32_isvalid methods wrap the corresponding tryparse methods. - The jl_strtod, jl_strtof, ... functions are wrappers over the jl_try_str... functions. This should fix JuliaLang#10498 as well. Ref: discussions at JuliaLang#9316, JuliaLang#3631, JuliaLang#5704
Could you move this branch to JuliaLang so I can work on it too? |
@nalimilan Parsing numbers seems to be unusual in that (1) it is very performance-critical, (2) it has a failure mode that is exactly halfway to needing an exception. Half the time, you want an exception if the string is not a number, and half the time it just means you will handle the string differently. That's why I think parse/tryparse is justified. |
Ok. Moved to the |
replaced by #10543 |
Introduces methods that parse a string as the indicated type and return a
Nullable
with the result instead of throwing exception:maybeint{T<:Integer}(::Type{T<:Integer},s::AbstractString)
maybefloat32(s::AbstractString)
andmaybefloat64(s::AbstractString)
Ref: discussions at #9316, #3631, #5704