159
159
160
160
function _pfmt_f (out:: IO , fs:: FormatSpec , x:: AbstractFloat )
161
161
# 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)
164
163
sch = _signchar (x, fs. sign)
165
164
intv = trunc (Integer, rax)
166
165
decv = rax - intv
@@ -191,6 +190,10 @@ function _pfmt_floate(out::IO, sch::AbstractChar, zs::Integer, u::Real, prec::In
191
190
ec:: AbstractChar )
192
191
intv = trunc (Integer, u)
193
192
decv = u - intv
193
+ if intv == 0 && decv != 0
194
+ intv = 1
195
+ decv -= 1
196
+ end
194
197
_pfmt_float (out, sch, zs, intv, decv, prec)
195
198
print (out, ec)
196
199
if e >= 0
@@ -203,36 +206,6 @@ function _pfmt_floate(out::IO, sch::AbstractChar, zs::Integer, u::Real, prec::In
203
206
_pfmt_intdigits (out, e, _Dec ())
204
207
end
205
208
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
-
236
209
function _pfmt_e (out:: IO , fs:: FormatSpec , x:: AbstractFloat )
237
210
# extract sign, significand, and exponent
238
211
ax = abs (x)
@@ -241,7 +214,7 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
241
214
e = 0
242
215
u = zero (x)
243
216
else
244
- rax = signif (ax, fs . prec + 1 ) # round(ax; sigdigits = fs.prec + 1)
217
+ rax = Compat . round (ax, sigdigits = fs. prec + 1 )
245
218
e = floor (Integer, log10 (rax)) # exponent
246
219
u = rax * exp10 (- e) # significand
247
220
end
0 commit comments