Skip to content

Commit 059cc48

Browse files
committed
Modified the number of digits to display to ensure correct round-trip.
1 parent 458829d commit 059cc48

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/Floatmu.jl

+22-19
Original file line numberDiff line numberDiff line change
@@ -981,28 +981,31 @@ end
981981
# Hack to use @printf with a format depending on the `Floatmu` used.
982982
# Since @printf is a macro, it cannot be called with anything other than a constant
983983
# for the format string.
984-
variable_printf(io,x::Floatmu{szE,2}) where {szE} = @printf(io,"%.3g",convert(Float64,x))
984+
# The number of digits used to display a value is chosen so as to ensure
985+
# a correct round-trip (``In-and-out conversions'', David Matula,
986+
# Comm. ACM, 11(1), Jan. 1968)
987+
variable_printf(io,x::Floatmu{szE,2}) where {szE} = @printf(io,"%.2g",convert(Float64,x))
985988
variable_printf(io,x::Floatmu{szE,3}) where {szE} = @printf(io,"%.3g",convert(Float64,x))
986989
variable_printf(io,x::Floatmu{szE,4}) where {szE} = @printf(io,"%.3g",convert(Float64,x))
987990
variable_printf(io,x::Floatmu{szE,5}) where {szE} = @printf(io,"%.3g",convert(Float64,x))
988-
variable_printf(io,x::Floatmu{szE,6}) where {szE} = @printf(io,"%.3g",convert(Float64,x))
989-
variable_printf(io,x::Floatmu{szE,7}) where {szE} = @printf(io,"%.3g",convert(Float64,x))
990-
variable_printf(io,x::Floatmu{szE,8}) where {szE} = @printf(io,"%.3g",convert(Float64,x))
991-
variable_printf(io,x::Floatmu{szE,9}) where {szE} = @printf(io,"%.4g",convert(Float64,x))
992-
variable_printf(io,x::Floatmu{szE,10}) where {szE} = @printf(io,"%.4g",convert(Float64,x))
993-
variable_printf(io,x::Floatmu{szE,11}) where {szE} = @printf(io,"%.4g",convert(Float64,x))
994-
variable_printf(io,x::Floatmu{szE,12}) where {szE} = @printf(io,"%.4g",convert(Float64,x))
995-
variable_printf(io,x::Floatmu{szE,13}) where {szE} = @printf(io,"%.5g",convert(Float64,x))
996-
variable_printf(io,x::Floatmu{szE,14}) where {szE} = @printf(io,"%.5g",convert(Float64,x))
997-
variable_printf(io,x::Floatmu{szE,15}) where {szE} = @printf(io,"%.5g",convert(Float64,x))
998-
variable_printf(io,x::Floatmu{szE,16}) where {szE} = @printf(io,"%.6g",convert(Float64,x))
999-
variable_printf(io,x::Floatmu{szE,17}) where {szE} = @printf(io,"%.6g",convert(Float64,x))
1000-
variable_printf(io,x::Floatmu{szE,18}) where {szE} = @printf(io,"%.6g",convert(Float64,x))
1001-
variable_printf(io,x::Floatmu{szE,19}) where {szE} = @printf(io,"%.7g",convert(Float64,x))
1002-
variable_printf(io,x::Floatmu{szE,20}) where {szE} = @printf(io,"%.7g",convert(Float64,x))
1003-
variable_printf(io,x::Floatmu{szE,21}) where {szE} = @printf(io,"%.7g",convert(Float64,x))
1004-
variable_printf(io,x::Floatmu{szE,22}) where {szE} = @printf(io,"%.7g",convert(Float64,x))
1005-
variable_printf(io,x::Floatmu{szE,23}) where {szE} = @printf(io,"%.7g",convert(Float64,x))
991+
variable_printf(io,x::Floatmu{szE,6}) where {szE} = @printf(io,"%.4g",convert(Float64,x))
992+
variable_printf(io,x::Floatmu{szE,7}) where {szE} = @printf(io,"%.4g",convert(Float64,x))
993+
variable_printf(io,x::Floatmu{szE,8}) where {szE} = @printf(io,"%.4g",convert(Float64,x))
994+
variable_printf(io,x::Floatmu{szE,9}) where {szE} = @printf(io,"%.5g",convert(Float64,x))
995+
variable_printf(io,x::Floatmu{szE,10}) where {szE} = @printf(io,"%.5g",convert(Float64,x))
996+
variable_printf(io,x::Floatmu{szE,11}) where {szE} = @printf(io,"%.5g",convert(Float64,x))
997+
variable_printf(io,x::Floatmu{szE,12}) where {szE} = @printf(io,"%.5g",convert(Float64,x))
998+
variable_printf(io,x::Floatmu{szE,13}) where {szE} = @printf(io,"%.6g",convert(Float64,x))
999+
variable_printf(io,x::Floatmu{szE,14}) where {szE} = @printf(io,"%.6g",convert(Float64,x))
1000+
variable_printf(io,x::Floatmu{szE,15}) where {szE} = @printf(io,"%.6g",convert(Float64,x))
1001+
variable_printf(io,x::Floatmu{szE,16}) where {szE} = @printf(io,"%.7g",convert(Float64,x))
1002+
variable_printf(io,x::Floatmu{szE,17}) where {szE} = @printf(io,"%.7g",convert(Float64,x))
1003+
variable_printf(io,x::Floatmu{szE,18}) where {szE} = @printf(io,"%.7g",convert(Float64,x))
1004+
variable_printf(io,x::Floatmu{szE,19}) where {szE} = @printf(io,"%.8g",convert(Float64,x))
1005+
variable_printf(io,x::Floatmu{szE,20}) where {szE} = @printf(io,"%.8g",convert(Float64,x))
1006+
variable_printf(io,x::Floatmu{szE,21}) where {szE} = @printf(io,"%.8g",convert(Float64,x))
1007+
variable_printf(io,x::Floatmu{szE,22}) where {szE} = @printf(io,"%.8g",convert(Float64,x))
1008+
variable_printf(io,x::Floatmu{szE,23}) where {szE} = @printf(io,"%.9g",convert(Float64,x))
10061009

10071010

10081011
function show(io::IO, x::Floatmu{szE,szf}) where {szE, szf}

0 commit comments

Comments
 (0)