Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Showoff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function scientific_precision_heuristic(xs::AbstractArray{<:AbstractFloat})
end


function showoff(xs::AbstractArray{<:AbstractFloat}, style=:auto)
function showoff(xs::AbstractArray{<:AbstractFloat}, style=:auto; export_raw=false)
x_min = concrete_minimum(xs)
x_max = concrete_maximum(xs)
x_min = Float64(x_min)
Expand All @@ -103,11 +103,11 @@ function showoff(xs::AbstractArray{<:AbstractFloat}, style=:auto)
return String[format_fixed(x, precision) for x in xs]
elseif style == :scientific
precision = scientific_precision_heuristic(xs)
return String[format_fixed_scientific(x, precision, false)
return String[format_fixed_scientific(x, precision, false, export_raw)
for x in xs]
elseif style == :engineering
precision = scientific_precision_heuristic(xs)
return String[format_fixed_scientific(x, precision, true)
return String[format_fixed_scientific(x, precision, true, export_raw)
for x in xs]
else
throw(ArgumentError("$(style) is not a recongnized number format"))
Expand Down
42 changes: 23 additions & 19 deletions src/ryu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end
# Print a floating point number in scientific notation at fixed precision. Sort of equivalent
# to @sprintf("%0.$(precision)e", x), but prettier printing.
function format_fixed_scientific(x::AbstractFloat, precision::Integer,
engineering::Bool)
engineering::Bool, export_raw::Bool=false)
if iszero(x)
return "0"
elseif isinf(x)
Expand All @@ -53,31 +53,35 @@ function format_fixed_scientific(x::AbstractFloat, precision::Integer,
end


buf = IOBuffer()
if export_raw #if export base_digits and power separately.
return e_format_number
else
buf = IOBuffer()

print(buf, base_digits)
print(buf, "×10")
print(buf, base_digits)
print(buf, "×10")

if power[1] == '-'
print(buf, '⁻')
end
leading_index = findfirst(c -> '1' <= c <= '9', power)
if power[1] == '-'
print(buf, '⁻')
end
leading_index = findfirst(c -> '1' <= c <= '9', power)

if leading_index === nothing
print(buf, superscript_numerals[1])
return String(take!(buf))
end
if leading_index === nothing
print(buf, superscript_numerals[1])
return String(take!(buf))
end

for digit in power[leading_index:end]
if digit == '-'
print(buf, '⁻')
elseif '0' <= digit <= '9'
print(buf, superscript_numerals[digit - '0' + 1])
end

for digit in power[leading_index:end]
if digit == '-'
print(buf, '⁻')
elseif '0' <= digit <= '9'
print(buf, superscript_numerals[digit - '0' + 1])
end

return String(take!(buf))
end

return String(take!(buf))
end


Expand Down