• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37527

pending completion
#37527

push

local

web-flow
make `IRShow.method_name` inferrable (#49607)

18 of 18 new or added lines in 3 files covered. (100.0%)

68710 of 81829 relevant lines covered (83.97%)

33068903.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.35
/base/ryu/exp.jl
1
function writeexp(buf, pos, v::T,
528✔
2
    precision=-1, plus=false, space=false, hash=false,
3
    expchar=UInt8('e'), decchar=UInt8('.'), trimtrailingzeros=false) where {T <: Base.IEEEFloat}
4
    @assert 0 < pos <= length(buf)
528✔
5
    startpos = pos
271✔
6
    x = Float64(v)
271✔
7
    pos = append_sign(x, plus, space, buf, pos)
489✔
8

9
    # special cases
10
    if x == 0
271✔
11
        buf[pos] = UInt8('0')
6✔
12
        pos += 1
6✔
13
        if precision > 0 && !trimtrailingzeros
6✔
14
            buf[pos] = decchar
6✔
15
            pos += 1
6✔
16
            for _ = 1:precision
12✔
17
                buf[pos] = UInt8('0')
90✔
18
                pos += 1
90✔
19
            end
174✔
20
        elseif hash
×
21
            buf[pos] = decchar
×
22
            pos += 1
×
23
        end
24
        buf[pos] = expchar
6✔
25
        buf[pos + 1] = UInt8('+')
6✔
26
        buf[pos + 2] = UInt8('0')
6✔
27
        buf[pos + 3] = UInt8('0')
6✔
28
        return pos + 4
6✔
29
    elseif isnan(x)
265✔
30
        buf[pos] = UInt8('N')
10✔
31
        buf[pos + 1] = UInt8('a')
10✔
32
        buf[pos + 2] = UInt8('N')
10✔
33
        return pos + 3
10✔
34
    elseif !isfinite(x)
255✔
35
        buf[pos] = UInt8('I')
12✔
36
        buf[pos + 1] = UInt8('n')
12✔
37
        buf[pos + 2] = UInt8('f')
12✔
38
        return pos + 3
12✔
39
    end
40

41
    bits = Core.bitcast(UInt64, x)
243✔
42
    mant = bits & MANTISSA_MASK
243✔
43
    exp = Int((bits >> 52) & EXP_MASK)
243✔
44

45
    if exp == 0
243✔
46
        e2 = 1 - 1023 - 52
×
47
        m2 = mant
×
48
    else
49
        e2 = exp - 1023 - 52
243✔
50
        m2 = (Int64(1) << 52) | mant
243✔
51
    end
52
    nonzero = false
243✔
53
    precision += 1
243✔
54
    digits = 0
243✔
55
    printedDigits = 0
243✔
56
    availableDigits = 0
243✔
57
    e = 0
243✔
58
    if e2 >= -52
243✔
59
        idx = e2 < 0 ? 0 : indexforexp(e2)
249✔
60
        p10bits = pow10bitsforindex(idx)
232✔
61
        len = lengthforindex(idx)
232✔
62
        i = len - 1
232✔
63
        while i >= 0
658✔
64
            j = p10bits - e2
461✔
65
            #=@inbounds=# mula, mulb, mulc = POW10_SPLIT[POW10_OFFSET[idx + 1] + i + 1]
461✔
66
            digits = mulshiftmod1e9(m2 << 8, mula, mulb, mulc, j + 8)
461✔
67
            if printedDigits != 0
461✔
68
                if printedDigits + 9 > precision
8✔
69
                    availableDigits = 9
8✔
70
                    break
8✔
71
                end
72
                pos = append_nine_digits(digits, buf, pos)
×
73
                printedDigits += 9
×
74
            elseif digits != 0
453✔
75
                availableDigits = decimallength(digits)
464✔
76
                e = i * 9 + availableDigits - 1
232✔
77
                if availableDigits > precision
232✔
78
                    break
27✔
79
                end
80
                if precision > 1
205✔
81
                    pos = append_d_digits(availableDigits, digits, buf, pos, decchar)
163✔
82
                else
83
                    buf[pos] = UInt8('0') + digits
42✔
84
                    pos += 1
42✔
85
                    if hash
42✔
86
                        buf[pos] = decchar
39✔
87
                        pos += 1
39✔
88
                    end
89
                end
90
                printedDigits = availableDigits
205✔
91
                availableDigits = 0
205✔
92
            end
93
            i -= 1
426✔
94
        end
426✔
95
    end
96
    if e2 < 0 && availableDigits == 0
243✔
97
        idx = div(-e2, 16)
208✔
98
        i = MIN_BLOCK_2[idx + 1]
208✔
99
        while i < 200
424✔
100
            j = 120 + (-e2 - 16 * idx)
216✔
101
            p = POW10_OFFSET_2[idx + 1] + i - MIN_BLOCK_2[idx + 1]
424✔
102
            if p >= POW10_OFFSET_2[idx + 2]
424✔
103
                digits = 0
×
104
            else
105
                #=@inbounds=# mula, mulb, mulc = POW10_SPLIT_2[p + 1]
424✔
106
                digits = mulshiftmod1e9(m2 << 8, mula, mulb, mulc, j + 8)
216✔
107
            end
108
            if printedDigits != 0
216✔
109
                if printedDigits + 9 > precision
205✔
110
                    availableDigits = 9
202✔
111
                    break
202✔
112
                end
113
                pos = append_nine_digits(digits, buf, pos)
6✔
114
                printedDigits += 9
3✔
115
            elseif digits != 0
22✔
116
                availableDigits = decimallength(digits)
11✔
117
                e = -(i + 1) * 9 + availableDigits - 1
22✔
118
                if availableDigits > precision
11✔
119
                    break
6✔
120
                end
121
                if precision > 1
5✔
122
                    pos = append_d_digits(availableDigits, digits, buf, pos, decchar)
10✔
123
                else
124
                    buf[pos] = UInt8('0') + digits
×
125
                    pos += 1
×
126
                    if hash
×
127
                        buf[pos] = decchar
×
128
                        pos += 1
×
129
                    end
130
                end
131
                printedDigits = availableDigits
5✔
132
                availableDigits = 0
5✔
133
            end
134
            i += 1
16✔
135
        end
8✔
136
    end
137
    maximum = precision - printedDigits
243✔
138
    if availableDigits == 0
243✔
139
        digits = 0
×
140
    end
141
    lastDigit = 0
243✔
142
    if availableDigits > maximum
243✔
143
        for k = 0:(availableDigits - maximum - 1)
486✔
144
            lastDigit = digits % 10
3,202✔
145
            digits = div(digits, 10)
3,202✔
146
        end
2,959✔
147
    end
148
    roundUp = 0
243✔
149
    if lastDigit != 5
486✔
150
        roundUp = lastDigit > 5
474✔
151
    else
152
        rexp = precision - e
6✔
153
        requiredTwos = -e2 - rexp
6✔
154
        trailingZeros = requiredTwos <= 0 ||
9✔
155
            (requiredTwos < 60 && pow2(m2, requiredTwos))
156
        if rexp < 0
6✔
157
            requiredFives = -rexp
3✔
158
            trailingZeros = trailingZeros & pow5(m2, requiredFives)
3✔
159
        end
160
        roundUp = trailingZeros ? 2 : 1
6✔
161
    end
162
    if printedDigits != 0
243✔
163
        if digits == 0
420✔
164
            for _ = 1:maximum
116✔
165
                buf[pos] = UInt8('0')
139✔
166
                pos += 1
139✔
167
            end
244✔
168
        else
169
            pos = append_c_digits(maximum, digits, buf, pos)
338✔
170
        end
171
    else
172
        if precision > 1
33✔
173
            pos = append_d_digits(maximum, digits, buf, pos, decchar)
26✔
174
        else
175
            buf[pos] = UInt8('0') + digits
7✔
176
            pos += 1
7✔
177
            if hash
7✔
178
                buf[pos] = decchar
3✔
179
                pos += 1
3✔
180
            end
181
        end
182
    end
183
    if roundUp != 0
249✔
184
        roundPos = pos
45✔
185
        while true
89✔
186
            roundPos -= 1
89✔
187
            if roundPos == (startpos - 1) || buf[roundPos] == UInt8('-') || (plus && buf[roundPos] == UInt8('+')) || (space && buf[roundPos] == UInt8(' '))
175✔
188
                buf[roundPos + 1] = UInt8('1')
5✔
189
                e += 1
5✔
190
                break
5✔
191
            end
192
            c = roundPos > 0 ? buf[roundPos] : 0x00
84✔
193
            if c == decchar
84✔
194
                continue
8✔
195
            elseif c == UInt8('9')
76✔
196
                buf[roundPos] = UInt8('0')
36✔
197
                roundUp = 1
36✔
198
                continue
36✔
199
            else
200
                if roundUp == 2 && UInt8(c) % 2 == 0
56✔
201
                    break
×
202
                end
203
                buf[roundPos] = c + 1
40✔
204
                break
40✔
205
            end
206
        end
44✔
207
    end
208
    if trimtrailingzeros
243✔
209
        while buf[pos - 1] == UInt8('0')
24✔
210
            pos -= 1
13✔
211
        end
13✔
212
        if buf[pos - 1] == decchar && !hash
11✔
213
            pos -= 1
×
214
        end
215
    end
216
    buf[pos] = expchar
243✔
217
    pos += 1
243✔
218
    if e < 0
243✔
219
        buf[pos] = UInt8('-')
8✔
220
        pos += 1
8✔
221
        e = -e
8✔
222
    else
223
        buf[pos] = UInt8('+')
235✔
224
        pos += 1
235✔
225
    end
226
    if e >= 100
243✔
227
        c = e % 10
15✔
228
        unsafe_copyto!(buf, pos, DIGIT_TABLE, 2 * div(e, 10) + 1, 2)
15✔
229
        buf[pos + 2] = UInt8('0') + c
15✔
230
        pos += 3
15✔
231
    else
232
        unsafe_copyto!(buf, pos, DIGIT_TABLE, 2 * e + 1, 2)
228✔
233
        pos += 2
228✔
234
    end
235
    return pos
243✔
236
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc