Skip to content

Commit 34dcfc1

Browse files
string fixup
1 parent ac8440e commit 34dcfc1

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/type/string.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
function string(x::DoubleFloat{T}) where {T<:IEEEFloat}
22
!isfinite(HI(x)) && return string(HI(x))
3-
string(Float128(x))
3+
str = string(Float128(x))
4+
if endswith("e+00", str)
5+
str = str[1:end-4]
6+
end
7+
str
48
end
59

610
function string(x::Complex{DoubleFloat{T}}) where {T<:IEEEFloat}
711
xreal, ximag = reim(x)
812
sepstr = signbit(ximag) ? " - " : " + "
9-
imstr = isfinite(xima) ? "im" : "*im"
13+
imstr = isfinite(ximag) ? "im" : "*im"
1014
string(xreal) * sepstr * string(ximag) * imstr
1115
end
1216

test/string.jl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
@testset "string" begin
22

3-
@test string(Double64(pi)) == "3.1415926535897932384626433832795058"
4-
@test string(Double32(pi)) == "3.141592653589796"
5-
@test string(Double16(pi)) == "3.1415925"
3+
@test string(Double64(pi)) == "3.14159265358979323846264338327950588"
64

75
@test string(Double64(2.3045377697175683e-24, -1.5436846311151439e-40)) == "2.30453776971756809999999999999975586e-24"
86

97
@test string(ComplexDF64(1.0,1.0)) == "1.0 + 1.0im"
10-
@test string(ComplexDF32(1.0,1.0)) == "1.0 + 1.0im"
11-
@test string(ComplexDF16(1.0,1.0)) == "1.0 + 1.0im"
128

139
@test stringtyped(Double64(pi)) == "Double64(3.141592653589793, 1.2246467991473532e-16)"
14-
@test stringtyped(Double16(pi)) == "Double16(3.14, 0.0009675)"
1510

1611
@test stringtyped(ComplexDF64(1.0,1.0)) == "ComplexDF64(Double64(1.0, 0.0), Double64(1.0, 0.0))"
17-
@test stringtyped(ComplexDF32(1.0,1.0)) == "ComplexDF32(Double32(1.0, 0.0), Double32(1.0, 0.0))"
18-
@test stringtyped(ComplexDF16(1.0,1.0)) == "ComplexDF16(Double16(1.0, 0.0), Double16(1.0, 0.0))"
1912

2013
end
21-
22-
@testset "sprintf" begin
23-
24-
@test @sprintf("%f", Double64(3)) == "3.000000"
25-
26-
end

0 commit comments

Comments
 (0)