Skip to content

Commit

Permalink
accept AbstractString for BigFloat construction (JuliaLang#28169)
Browse files Browse the repository at this point in the history
This is a minor change to allow `BigFloat` construction from `AbstractString`. E.g.:

```
julia> BigFloat(strip(" 42"))
4.2e+01
```

Without this:

```
julia> BigFloat(strip(" 42"))
ERROR: MethodError: Cannot `convert` an object of type SubString{String} to an object of type BigFloat
...
```
  • Loading branch information
tanmaykm authored and KristofferC committed Jul 19, 2018
1 parent 68366d6 commit 91c2da8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ end
Create a representation of the string `x` as a [`BigFloat`](@ref).
"""
BigFloat(x::String) = parse(BigFloat, x)
BigFloat(x::AbstractString) = parse(BigFloat, x)


## BigFloat -> Integer
Expand Down
2 changes: 1 addition & 1 deletion test/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Base.MPFR
@test x == BigFloat(x) == BigFloat(0xc) == BigFloat(12.) ==
BigFloat(BigInt(12)) == BigFloat(BigFloat(12)) == parse(BigFloat,"12") ==
parse(BigFloat,"12 ") == parse(BigFloat," 12") == parse(BigFloat," 12 ") ==
BigFloat(Float32(12.)) == BigFloat(12//1)
BigFloat(Float32(12.)) == BigFloat(12//1) == BigFloat(SubString("12"))

@test typeof(BigFloat(typemax(Int8))) == BigFloat
@test typeof(BigFloat(typemax(Int16))) == BigFloat
Expand Down

0 comments on commit 91c2da8

Please sign in to comment.