@@ -309,6 +309,8 @@ function convert(::Type{TR}, x::FD{T, f}) where {TR <: Rational, T, f}
309309 convert (TR, x. i // coefficient (FD{T, f})):: TR
310310end
311311
312+ (:: Type{T} )(x:: FD ) where {T<: Union{AbstractFloat,Integer,Rational} } = convert (T, x)
313+
312314promote_rule (:: Type{FD{T, f}} , :: Type{<:Integer} ) where {T, f} = FD{T, f}
313315promote_rule (:: Type{<:FD} , :: Type{TF} ) where {TF <: AbstractFloat } = TF
314316promote_rule (:: Type{<:FD} , :: Type{Rational{TR}} ) where {TR} = Rational{TR}
@@ -385,18 +387,18 @@ function parse(::Type{FD{T, f}}, str::AbstractString, mode::RoundingMode=RoundNe
385387 end
386388
387389 # Parse exponent information
388- exp_index = findfirst (equalto (' e' ), str)
390+ exp_index = coalesce ( findfirst (== (' e' ), str), 0 )
389391 if exp_index > 0
390392 exp = parse (Int, str[(exp_index + 1 ): end ])
391393 sig_end = exp_index - 1
392394 else
393395 exp = 0
394- sig_end = endof (str)
396+ sig_end = lastindex (str)
395397 end
396398
397399 # Remove the decimal place from the string
398400 sign = T (first (str) == ' -' ? - 1 : 1 )
399- dec_index = findfirst (equalto (' .' ), str)
401+ dec_index = coalesce ( findfirst (== (' .' ), str), 0 )
400402 sig_start = sign < 0 ? 2 : 1
401403 if dec_index > 0
402404 int_str = str[sig_start: (dec_index - 1 )] * str[(dec_index + 1 ): sig_end]
@@ -407,15 +409,15 @@ function parse(::Type{FD{T, f}}, str::AbstractString, mode::RoundingMode=RoundNe
407409
408410 # Split the integer string into the value we can represent inside the FixedDecimal and
409411 # the remaining digits we'll use during rounding
410- int_end = endof (int_str)
412+ int_end = lastindex (int_str)
411413 pivot = int_end + exp - (- f)
412414
413415 a = rpad (int_str[1 : min (pivot, int_end)], pivot, ' 0' )
414416 b = lpad (int_str[max (pivot, 1 ): int_end], int_end - pivot + 1 , ' 0' )
415417
416418 # Parse the strings
417419 val = isempty (a) ? T (0 ) : sign * parse (T, a)
418- if ! isempty (b) && any (collect ( b[2 : end ]) .!= ' 0 ' )
420+ if ! isempty (b) && any (! isequal ( ' 0 ' ), b[2 : end ])
419421 if mode == RoundThrows
420422 throw (InexactError (:parse , FD{T, f}, str))
421423 elseif mode == RoundNearest
0 commit comments