Skip to content

Commit 0603207

Browse files
authored
Merge pull request #41 from JuliaString/spj/merge
Merge in recent PRs from JuliaIO/Formatting.jl
2 parents 04b5040 + 031f275 commit 0603207

File tree

7 files changed

+44
-46
lines changed

7 files changed

+44
-46
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.jl.cov
2+
*.jl.*.cov
3+
*.jl.mem

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ matrix:
2121

2222
# uncomment the following lines to override the default test script
2323
#script:
24-
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
25-
# - julia -e 'if VERSION < v"0.7.0-DEV.5183" ; Pkg.add("Compat") ; Pkg.clone(pwd()) ; else ; Pkg.up() ; end ; Pkg.test("Format"; coverage=true)'
24+
2625
after_success:
2726
- julia -e 'VERSION < v"0.7.0-DEV" || (using Pkg); cd(Pkg.dir("Format")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder()); Codecov.submit(Codecov.process_folder())'

Project.toml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1-
authors = ["ScottPJones <[email protected]>"]
1+
authors = [
2+
"Dahua Lin <[email protected]>",
3+
"John M Kuhn <[email protected]>",
4+
"ScottPJones <[email protected]>",
5+
"Thomas Breloff <[email protected]>",
6+
"Alex Arslan <[email protected]>",
7+
"Chuan-Zheng Lee <[email protected]>",
8+
"Galen Lynch <[email protected]>",
9+
"Iain Dunning <[email protected]>",
10+
"Joseph Kleinhenz <[email protected]>",
11+
"Keno Fischer <[email protected]>",
12+
"Kevin Squire <[email protected]>",
13+
"Theodore Papamarkou <[email protected]>",
14+
"Tony Fong <[email protected]>",
15+
"Tony Kelman <[email protected]>",
16+
"Viral B. Shah <[email protected]>",
17+
"Yichao Yu <[email protected]>",
18+
19+
"ranjanan <[email protected]>"
20+
]
221
desc = "C, Python, and type-defined numeric and string formatting"
322
keywords = ["Strings", "Formatting"]
423
license = "MIT"
524
name = "Format"
625
uuid = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
26+
version = "0.7.2"
727

828
[deps]
9-
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
29+
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
30+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
31+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
julia 0.6
1+
julia 0.6 2-
22
Compat 1.0.1

appveyor.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ platform:
1111

1212
## uncomment the following lines to allow failures on nightly julia
1313
## (tests will run but not make your overall status red)
14-
#matrix:
15-
# allow_failures:
16-
# - julia_version: latest
14+
matrix:
15+
allow_failures:
16+
- julia_version: 1.0
17+
- julia_version: latest
1718

1819
branches:
1920
only:

src/cformat.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ function format( x::T;
190190
(1024.0 ^8, "Yi" ),
191191
(1024.0 ^7, "Zi" ),
192192
(1024.0 ^6, "Ei" ),
193-
(1024^5, "Pi" ),
194-
(1024^4, "Ti" ),
195-
(1024^3, "Gi"),
196-
(1024^2, "Mi"),
197-
(1024, "Ki")
193+
(1024.0 ^5, "Pi" ),
194+
(1024.0 ^4, "Ti" ),
195+
(1024.0 ^3, "Gi"),
196+
(1024.0 ^2, "Mi"),
197+
(1024.0, "Ki")
198198
]
199199
else # :finance
200200
scales = [

src/fmtcore.jl

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ end
159159

160160
function _pfmt_f(out::IO, fs::FormatSpec, x::AbstractFloat)
161161
# separate sign, integer, and decimal part
162-
rax = (@static VERSION < v"0.7.0-DEV.4804" ? round(abs(x), fs.prec) :
163-
round(abs(x); digits=fs.prec))
162+
rax = Compat.round(abs(x), digits = fs.prec)
164163
sch = _signchar(x, fs.sign)
165164
intv = trunc(Integer, rax)
166165
decv = rax - intv
@@ -191,6 +190,10 @@ function _pfmt_floate(out::IO, sch::AbstractChar, zs::Integer, u::Real, prec::In
191190
ec::AbstractChar)
192191
intv = trunc(Integer, u)
193192
decv = u - intv
193+
if intv == 0 && decv != 0
194+
intv = 1
195+
decv -= 1
196+
end
194197
_pfmt_float(out, sch, zs, intv, decv, prec)
195198
print(out, ec)
196199
if e >= 0
@@ -203,36 +206,6 @@ function _pfmt_floate(out::IO, sch::AbstractChar, zs::Integer, u::Real, prec::In
203206
_pfmt_intdigits(out, e, _Dec())
204207
end
205208

206-
# Pull in definition of signif from v0.6.2 base, since it is currently broken for
207-
# BigFloat and DecFP (at least) on master
208-
209-
@static if VERSION >= v"0.7.0-DEV.4804"
210-
# adapted from Matlab File Exchange roundsd: http://www.mathworks.com/matlabcentral/fileexchange/26212
211-
# for round, og is the power of 10 relative to the decimal point
212-
# for signif, og is the absolute power of 10
213-
# digits and base must be integers, x must be convertable to float
214-
215-
function signif(x::Real, digits::Integer, base::Integer=10)
216-
digits < 1 && throw(DomainError())
217-
218-
x = float(x)
219-
(x == 0 || !isfinite(x)) && return x
220-
if base == 10
221-
e = floor(log10(abs(x)) - digits + 1.)
222-
og = oftype(x, exp10(abs(e)))
223-
elseif base == 2
224-
e = exponent(abs(x)) - digits + 1.
225-
og = oftype(x, exp2(abs(e)))
226-
else
227-
e = floor(log(base, abs(x)) - digits + 1.)
228-
og = oftype(x, float(base) ^ abs(e))
229-
end
230-
# for numeric stability
231-
r = e >= 0 ? round(x/og)*og : round(x*og)/og
232-
isfinite(r) ? r : x
233-
end
234-
end
235-
236209
function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
237210
# extract sign, significand, and exponent
238211
ax = abs(x)
@@ -241,7 +214,7 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
241214
e = 0
242215
u = zero(x)
243216
else
244-
rax = signif(ax, fs.prec + 1) # round(ax; sigdigits = fs.prec + 1)
217+
rax = Compat.round(ax, sigdigits = fs.prec + 1)
245218
e = floor(Integer, log10(rax)) # exponent
246219
u = rax * exp10(-e) # significand
247220
end

0 commit comments

Comments
 (0)