Skip to content

Commit 41e0eb0

Browse files
authored
BigFloat: Print exponent without leading '+' and zeros (#58008)
Fixes #56941 With this small change we get: ```julia julia> big"1e6" 1.0e6 ```
1 parent b9a0497 commit 41e0eb0

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

base/mpfr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ function _prettify_bigfloat(s::String)::String
12291229
string(neg ? '-' : "", '0', '.', '0'^(-expo-1), int, frac == "0" ? "" : frac)
12301230
end
12311231
else
1232-
string(mantissa, 'e', exponent)
1232+
string(mantissa, 'e', expo)
12331233
end
12341234
end
12351235

doc/src/manual/integers-and-floating-point-numbers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ julia> parse(BigFloat, "1.23456789012345678901")
600600
1.234567890123456789010000000000000000000000000000000000000000000000000000000004
601601
602602
julia> BigFloat(2.0^66) / 3
603-
2.459565876494606882133333333333333333333333333333333333333333333333333333333344e+19
603+
2.459565876494606882133333333333333333333333333333333333333333333333333333333344e19
604604
605605
julia> factorial(BigInt(40))
606606
815915283247897734345611269596115894272000000000

test/mpfr.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,16 +667,19 @@ end
667667
@test string(parse(BigFloat, "0.1")) == "0.10000002"
668668
@test string(parse(BigFloat, "0.5")) == "0.5"
669669
@test string(parse(BigFloat, "-9.9")) == "-9.9000015"
670+
@test string(parse(BigFloat, "1e6")) == "1.0e6"
670671
end
671672
setprecision(40) do
672673
@test string(parse(BigFloat, "0.1")) == "0.10000000000002"
673674
@test string(parse(BigFloat, "0.5")) == "0.5"
674675
@test string(parse(BigFloat, "-9.9")) == "-9.8999999999942"
676+
@test string(parse(BigFloat, "1e6")) == "1.0e6"
675677
end
676678
setprecision(123) do
677679
@test string(parse(BigFloat, "0.1")) == "0.0999999999999999999999999999999999999953"
678680
@test string(parse(BigFloat, "0.5")) == "0.5"
679681
@test string(parse(BigFloat, "-9.9")) == "-9.8999999999999999999999999999999999997"
682+
@test string(parse(BigFloat, "1e6")) == "1.0e6"
680683
end
681684
end
682685
@testset "eps" begin
@@ -998,18 +1001,18 @@ end
9981001

9991002
test_show_bigfloat(big"1.23456789", contains_e=false, starts="1.23")
10001003
test_show_bigfloat(big"-1.23456789", contains_e=false, starts="-1.23")
1001-
test_show_bigfloat(big"2.3457645687563543266576889678956787e10000", starts="2.345", ends="e+10000")
1004+
test_show_bigfloat(big"2.3457645687563543266576889678956787e10000", starts="2.345", ends="e10000")
10021005
test_show_bigfloat(big"-2.3457645687563543266576889678956787e-10000", starts="-2.345", ends="e-10000")
10031006
test_show_bigfloat(big"42.0", contains_e=false, starts="42.0")
10041007
test_show_bigfloat(big"420.0", contains_e=false, starts="420.0") # '0's have to be added on the right before point
10051008
test_show_bigfloat(big"-420.0", contains_e=false, starts="-420.0")
10061009
test_show_bigfloat(big"420000.0", contains_e=false, starts="420000.0")
10071010
test_show_bigfloat(big"654321.0", contains_e=false, starts="654321.0")
10081011
test_show_bigfloat(big"-654321.0", contains_e=false, starts="-654321.0")
1009-
test_show_bigfloat(big"6543210.0", contains_e=true, starts="6.5", ends="e+06")
1012+
test_show_bigfloat(big"6543210.0", contains_e=true, starts="6.5", ends="e6")
10101013
test_show_bigfloat(big"0.000123", contains_e=false, starts="0.000123")
10111014
test_show_bigfloat(big"-0.000123", contains_e=false, starts="-0.000123")
1012-
test_show_bigfloat(big"0.00001234", contains_e=true, starts="1.23", ends="e-05")
1015+
test_show_bigfloat(big"0.00001234", contains_e=true, starts="1.23", ends="e-5")
10131016

10141017
for to_string in [string,
10151018
x->sprint(show, x),

0 commit comments

Comments
 (0)