@@ -8,7 +8,7 @@ import Base: ==, <, <=, -, +, *, /, ~, isapprox,
8
8
div, fld, rem, mod, mod1, fld1, min, max, minmax,
9
9
rand
10
10
11
- using Base. Checked: checked_add, checked_sub
11
+ using Base. Checked: checked_add, checked_sub, checked_div
12
12
13
13
using Base: @pure
14
14
@@ -151,6 +151,26 @@ for (m, f) in ((:(:Nearest), :round),
151
151
end
152
152
end
153
153
154
+ function Base. unsafe_length (r:: StepRange{X,X} ) where {X <: FixedPoint{<:ShorterThanInt} }
155
+ start, step, stop = reinterpret (r. start), reinterpret (r. step), reinterpret (r. stop)
156
+ return div (Int (stop) - Int (start) + Int (step), Int (step))
157
+ end
158
+ function Base. unsafe_length (r:: StepRange{X,X} ) where {X <: FixedPoint }
159
+ start, step, stop = reinterpret (r. start), reinterpret (r. step), reinterpret (r. stop)
160
+ return div ((stop - start) + step, step)
161
+ end
162
+ function Base. unsafe_length (r:: StepRange{<:FixedPoint} )
163
+ start, step, stop = float (r. start), r. step, float (r. stop)
164
+ return div ((stop - start) + step, step)
165
+ end
166
+ Base. length (r:: StepRange{X,X} ) where {X <: FixedPoint{<:ShorterThanInt} } =
167
+ Base. unsafe_length (r)
168
+ function Base. length (r:: StepRange{X,X} ) where {X <: FixedPoint }
169
+ start, step, stop = reinterpret (r. start), reinterpret (r. step), reinterpret (r. stop)
170
+ return checked_div (checked_add (checked_sub (stop, start), step), step)
171
+ end
172
+ Base. length (r:: StepRange{<:FixedPoint} ) = Base. unsafe_length (r)
173
+
154
174
# Printing. These are used to generate type-symbols, so we need them
155
175
# before we include any files.
156
176
function showtype (io:: IO , :: Type{X} ) where {X <: FixedPoint }
0 commit comments