@@ -203,6 +203,35 @@ function _pfmt_floate(out::IO, sch::AbstractChar, zs::Integer, u::Real, prec::In
203
203
_pfmt_intdigits (out, e, _Dec ())
204
204
end
205
205
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
206
235
207
236
function _pfmt_e (out:: IO , fs:: FormatSpec , x:: AbstractFloat )
208
237
# extract sign, significand, and exponent
@@ -212,8 +241,7 @@ function _pfmt_e(out::IO, fs::FormatSpec, x::AbstractFloat)
212
241
e = 0
213
242
u = zero (x)
214
243
else
215
- rax = (@static VERSION < v " 0.7.0-DEV.4804" ? signif (ax, fs. prec + 1 ) :
216
- round (ax; sigdigits = fs. prec + 1 ))
244
+ rax = signif (ax, fs. prec + 1 ) # round(ax; sigdigits = fs.prec + 1)
217
245
e = floor (Integer, log10 (rax)) # exponent
218
246
u = rax * exp10 (- e) # significand
219
247
end
0 commit comments