Skip to content

Commit ca5083e

Browse files
authored
small fixes for fast-math mode (#33)
* small fixes for fast-math mode * isnothing for version before 1.1 * move functions * update docstring * fix annotation and docstring
1 parent 9c8943d commit ca5083e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/ProgressBar.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function eta_seconds(bar)
2424
return total - (time() - bar.tfirst)
2525
end
2626

27+
2728
function printprogress(io::IO, bar::ProgressBar)
2829
if bar.name == ""
2930
desc = "Progress: "
@@ -43,7 +44,7 @@ function printprogress(io::IO, bar::ProgressBar)
4344
bar.barglyphs,
4445
bar.tfirst,
4546
desc,
46-
something(bar.fraction, NaN),
47+
bar.fraction,
4748
eta_seconds(bar),
4849
)
4950
end

src/ProgressMeter/ProgressMeter.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ BarGlyphs() = BarGlyphs(
2222
)
2323

2424
"""
25-
printprogress(io::IO, barglyphs::BarGlyphs, tfirst::Float64, desc, progress::Real)
25+
printprogress(io::IO, barglyphs::BarGlyphs, tfirst::Float64, desc, progress, eta_seconds::Real)
2626
2727
Print progress bar to `io`.
2828
@@ -31,24 +31,24 @@ Print progress bar to `io`.
3131
- `barglyphs::BarGlyphs`
3232
- `tfirst::Float64`
3333
- `desc`: description to be printed at left side of progress bar.
34-
- `progress::Real`: a number between 0 and 1 or a `NaN`.
34+
- `progress`: a number between 0 and 1 or `nothing`.
3535
- `eta_seconds::Real`: ETA in seconds
3636
"""
3737
function printprogress(
3838
io::IO,
3939
barglyphs::BarGlyphs,
4040
tfirst::Float64,
4141
desc,
42-
progress::Real,
42+
progress,
4343
eta_seconds::Real,
4444
)
4545
t = time()
46-
percentage_complete = 100.0 * (isnan(progress) ? 0.0 : progress)
46+
percentage_complete = 100.0 * (isnothing(progress) || isnan(progress) ? 0.0 : progress)
4747

4848
#...length of percentage and ETA string with days is 29 characters
4949
barlen = max(0, displaysize(io)[2] - (length(desc) + 29))
5050

51-
if progress >= 1
51+
if !isnothing(progress) && progress >= 1
5252
bar = barstring(barlen, percentage_complete, barglyphs=barglyphs)
5353
dur = durationstring(t - tfirst)
5454
@printf io "%s%3u%%%s Time: %s" desc round(Int, percentage_complete) bar dur
@@ -111,4 +111,12 @@ function durationstring(nsec)
111111
hhmmss
112112
end
113113

114+
# issue #31: isnothing require Julia 1.1
115+
# copy-over from
116+
# https://github.com/JuliaLang/julia/blob/0413ef0e4de83b41b637ba02cc63314da45fe56b/base/some.jl
117+
if !isdefined(Base, :isnothing)
118+
isnothing(::Any) = false
119+
isnothing(::Nothing) = true
120+
end
121+
114122
end

0 commit comments

Comments
 (0)