Skip to content

Commit

Permalink
Replace usages of Int#/ for Int#//
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardiff committed Apr 10, 2019
1 parent b5c435e commit 1c2b853
Show file tree
Hide file tree
Showing 43 changed files with 112 additions and 112 deletions.
8 changes: 4 additions & 4 deletions spec/std/deque_spec.cr
Expand Up @@ -75,21 +75,21 @@ describe "Deque" do
it "works the same as array when inserting at 1/8 size and deleting at 3/4 size" do
DequeTester.new.test do
1000.times do
step { c.insert(c.size / 8, i) }
step { c.insert(c.size // 8, i) }
end
1000.times do
step { c.delete_at(c.size * 3 / 4) }
step { c.delete_at(c.size * 3 // 4) }
end
end
end

it "works the same as array when inserting at 3/4 size and deleting at 1/8 size" do
DequeTester.new.test do
1000.times do
step { c.insert(c.size * 3 / 4, i) }
step { c.insert(c.size * 3 // 4, i) }
end
1000.times do
step { c.delete_at(c.size / 8) }
step { c.delete_at(c.size // 8) }
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/std/enumerable_spec.cr
Expand Up @@ -118,7 +118,7 @@ describe "Enumerable" do
[1, 2].chunk { false }.to_a.should eq [{false, [1, 2]}]
[1, 1, 2, 3, 3].chunk(&.itself).to_a.should eq [{1, [1, 1]}, {2, [2]}, {3, [3, 3]}]
[1, 1, 2, 3, 3].chunk(&.<=(2)).to_a.should eq [{true, [1, 1, 2]}, {false, [3, 3]}]
(0..10).chunk(&./(3)).to_a.should eq [{0, [0, 1, 2]}, {1, [3, 4, 5]}, {2, [6, 7, 8]}, {3, [9, 10]}]
(0..10).chunk(&.//(3)).to_a.should eq [{0, [0, 1, 2]}, {1, [3, 4, 5]}, {2, [6, 7, 8]}, {3, [9, 10]}]
end

it "work with class" do
Expand All @@ -132,7 +132,7 @@ describe "Enumerable" do
end

it "rewind" do
i = (0..10).chunk(&./(3))
i = (0..10).chunk(&.//(3))
i.next.should eq({0, [0, 1, 2]})
i.next.should eq({1, [3, 4, 5]})
end
Expand Down Expand Up @@ -193,15 +193,15 @@ describe "Enumerable" do
[1, 2].chunks { false }.should eq [{false, [1, 2]}]
[1, 1, 2, 3, 3].chunks(&.itself).should eq [{1, [1, 1]}, {2, [2]}, {3, [3, 3]}]
[1, 1, 2, 3, 3].chunks(&.<=(2)).should eq [{true, [1, 1, 2]}, {false, [3, 3]}]
(0..10).chunks(&./(3)).should eq [{0, [0, 1, 2]}, {1, [3, 4, 5]}, {2, [6, 7, 8]}, {3, [9, 10]}]
(0..10).chunks(&.//(3)).should eq [{0, [0, 1, 2]}, {1, [3, 4, 5]}, {2, [6, 7, 8]}, {3, [9, 10]}]
end

it "work with class" do
[1, 1, 2, 3, 3].chunks(&.class).should eq [{Int32, [1, 1, 2, 3, 3]}]
end

it "work with pure enumerable" do
SpecEnumerable.new.chunks(&./(2)).should eq [{0, [1]}, {1, [2, 3]}]
SpecEnumerable.new.chunks(&.//(2)).should eq [{0, [1]}, {1, [2, 3]}]
end

it "returns elements for which the block returns Enumerable::Chunk::Alone in separate Arrays" do
Expand Down
2 changes: 1 addition & 1 deletion spec/std/int_spec.cr
Expand Up @@ -429,7 +429,7 @@ describe "Int" do
it "holds true that x == q*y + r" do
[5, -5, 6, -6, 10, -10].each do |x|
[3, -3].each do |y|
q = x / y
q = x // y
r = x % y
(q*y + r).should eq(x)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/random/secure_spec.cr
Expand Up @@ -9,7 +9,7 @@ describe "Random::Secure" do
x.should be >= 123456
x.should be < 654321

Random::Secure.rand(Int64::MAX / 2).should be <= (Int64::MAX / 2)
Random::Secure.rand(Int64::MAX // 2).should be <= (Int64::MAX // 2)
end

it "fully fills a large buffer" do
Expand Down
22 changes: 11 additions & 11 deletions src/array.cr
Expand Up @@ -1474,7 +1474,7 @@ class Array(T)
return self if size == 0
n %= size
return self if n == 0
if n <= size / 2
if n <= size // 2
tmp = self[0..n]
@buffer.move_from(@buffer + n, size - n)
(@buffer + size - n).copy_from(tmp.to_unsafe, n)
Expand Down Expand Up @@ -1946,7 +1946,7 @@ class Array(T)
end

protected def self.heap_sort!(a, n)
(n / 2).downto 0 do |p|
(n // 2).downto 0 do |p|
heapify!(a, p, n)
end
while n > 1
Expand All @@ -1958,14 +1958,14 @@ class Array(T)

protected def self.heapify!(a, p, n)
v, c = a[p], p
while c < (n - 1) / 2
while c < (n - 1) // 2
c = 2 * (c + 1)
c -= 1 if cmp(a[c], a[c - 1]) < 0
break unless cmp(v, a[c]) <= 0
a[p] = a[c]
p = c
end
if n & 1 == 0 && c == n / 2 - 1
if n & 1 == 0 && c == n // 2 - 1
c = 2 * c + 1
if cmp(v, a[c]) < 0
a[p] = a[c]
Expand All @@ -1976,7 +1976,7 @@ class Array(T)
end

protected def self.center_median!(a, n)
b, c = a + n / 2, a + n - 1
b, c = a + n // 2, a + n - 1
if cmp(a.value, b.value) <= 0
if cmp(b.value, c.value) <= 0
return
Expand All @@ -1995,7 +1995,7 @@ class Array(T)
end

protected def self.partition_for_quick_sort!(a, n)
v, l, r = a[n / 2], a + 1, a + n - 1
v, l, r = a[n // 2], a + 1, a + n - 1
loop do
while cmp(l.value, v) < 0
l += 1
Expand Down Expand Up @@ -2044,7 +2044,7 @@ class Array(T)
end

protected def self.heap_sort!(a, n, comp)
(n / 2).downto 0 do |p|
(n // 2).downto 0 do |p|
heapify!(a, p, n, comp)
end
while n > 1
Expand All @@ -2056,14 +2056,14 @@ class Array(T)

protected def self.heapify!(a, p, n, comp)
v, c = a[p], p
while c < (n - 1) / 2
while c < (n - 1) // 2
c = 2 * (c + 1)
c -= 1 if cmp(a[c], a[c - 1], comp) < 0
break unless cmp(v, a[c], comp) <= 0
a[p] = a[c]
p = c
end
if n & 1 == 0 && c == n / 2 - 1
if n & 1 == 0 && c == n // 2 - 1
c = 2 * c + 1
if cmp(v, a[c], comp) < 0
a[p] = a[c]
Expand All @@ -2074,7 +2074,7 @@ class Array(T)
end

protected def self.center_median!(a, n, comp)
b, c = a + n / 2, a + n - 1
b, c = a + n // 2, a + n - 1
if cmp(a.value, b.value, comp) <= 0
if cmp(b.value, c.value, comp) <= 0
return
Expand All @@ -2093,7 +2093,7 @@ class Array(T)
end

protected def self.partition_for_quick_sort!(a, n, comp)
v, l, r = a[n / 2], a + 1, a + n - 1
v, l, r = a[n // 2], a + 1, a + n - 1
loop do
while l < a + n && cmp(l.value, v, comp) < 0
l += 1
Expand Down
2 changes: 1 addition & 1 deletion src/base64.cr
Expand Up @@ -191,7 +191,7 @@ module Base64

private def encode_size(str_size, new_lines = false)
size = (str_size * 4 / 3.0).to_i + 4
size += size / LINE_SIZE if new_lines
size += size // LINE_SIZE if new_lines
size
end

Expand Down
2 changes: 1 addition & 1 deletion src/big/big_int.cr
Expand Up @@ -696,7 +696,7 @@ module Random
needed_parts += 1
end

limit = rand_max / max * max
limit = rand_max // max * max

loop do
result = BigInt.new(next_u)
Expand Down
2 changes: 1 addition & 1 deletion src/bit_array.cr
Expand Up @@ -153,7 +153,7 @@ struct BitArray
else
ba = BitArray.new(count)
start_bit_index, start_sub_index = start.divmod(32)
end_bit_index = (start + count) / 32
end_bit_index = (start + count) // 32

i = 0
bits = @bits[start_bit_index]
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/debug.cr
Expand Up @@ -102,7 +102,7 @@ module Crystal
size = @program.target_machine.data_layout.size_in_bits(llvm_embedded_type(ivar_type))

# FIXME structs like LibC::PthreadMutexT generate huge offset values
next if offset > UInt64::MAX / 8u64
next if offset > UInt64::MAX // 8u64

member = di_builder.create_member_type(nil, name[1..-1], nil, 1, size, size, 8u64 * offset, LLVM::DIFlags::Zero, ivar_debug_type)
element_types << member
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/compiler.cr
Expand Up @@ -427,7 +427,7 @@ module Crystal
jobs_count = 0
wait_channel = Channel(Array(String)).new(@n_threads)

units.each_slice(Math.max(units.size / @n_threads, 1)) do |slice|
units.each_slice(Math.max(units.size // @n_threads, 1)) do |slice|
jobs_count += 1
spawn do
# For stats output we want to count how many previous
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/table_print.cr
Expand Up @@ -32,7 +32,7 @@ module Crystal
when :right
"%+#{available_width}s" % cell.text
when :center
left = " " * ((available_width - cell.text.size) / 2)
left = " " * ((available_width - cell.text.size) // 2)
right = " " * (available_width - cell.text.size - left.size)
"#{left}#{cell.text}#{right}"
end
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/types.cr
Expand Up @@ -1273,7 +1273,7 @@ module Crystal
end

def normal_rank
(@rank - 1) / 2
(@rank - 1) // 2
end

def range
Expand Down
4 changes: 2 additions & 2 deletions src/crystal/compiler_rt.cr
Expand Up @@ -26,11 +26,11 @@ fun __mulodi4(a : Int64, b : Int64, overflow : Int32*) : Int64
return result
end
if sa == sb
if abs_a > max / abs_b
if abs_a > max // abs_b
overflow.value = 1
end
else
if abs_a > min / (0i64 &- abs_b)
if abs_a > min // (0i64 &- abs_b)
overflow.value = 1
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/event.cr
Expand Up @@ -24,7 +24,7 @@ struct Crystal::Event
def add(timeout : Time::Span)
add LibC::Timeval.new(
tv_sec: LibC::TimeT.new(timeout.total_seconds),
tv_usec: timeout.nanoseconds / 1_000
tv_usec: timeout.nanoseconds // 1_000
)
end

Expand Down
2 changes: 1 addition & 1 deletion src/crystal/hasher.cr
Expand Up @@ -244,7 +244,7 @@ struct Crystal::Hasher
end

private def read_u24(ptr, rest)
ptr[0].to_u64 | (ptr[rest/2].to_u64 << 8) | (ptr[rest - 1].to_u64 << 16)
ptr[0].to_u64 | (ptr[rest//2].to_u64 << 8) | (ptr[rest - 1].to_u64 << 16)
end

private def read_u32(ptr)
Expand Down
2 changes: 1 addition & 1 deletion src/crystal/system/unix/file.cr
Expand Up @@ -125,7 +125,7 @@ module Crystal::System::File
private def self.to_timeval(time : ::Time)
t = uninitialized LibC::Timeval
t.tv_sec = typeof(t.tv_sec).new(time.to_unix)
t.tv_usec = typeof(t.tv_usec).new(time.nanosecond / ::Time::NANOSECONDS_PER_MICROSECOND)
t.tv_usec = typeof(t.tv_usec).new(time.nanosecond // ::Time::NANOSECONDS_PER_MICROSECOND)
t
end

Expand Down
4 changes: 2 additions & 2 deletions src/crystal/system/unix/time.cr
Expand Up @@ -28,8 +28,8 @@ module Crystal::System::Time
def self.monotonic : {Int64, Int32}
{% if flag?(:darwin) %}
info = mach_timebase_info
total_nanoseconds = LibC.mach_absolute_time * info.numer / info.denom
seconds = total_nanoseconds / 1_000_000_000
total_nanoseconds = LibC.mach_absolute_time * info.numer // info.denom
seconds = total_nanoseconds // 1_000_000_000
nanoseconds = total_nanoseconds.remainder(1_000_000_000)
{seconds.to_i64, nanoseconds.to_i32}
{% else %}
Expand Down
6 changes: 3 additions & 3 deletions src/debug/dwarf/line_numbers.cr
Expand Up @@ -266,7 +266,7 @@ module Debug
registers.address += {{operation_advance}} * sequence.minimum_instruction_length
else
registers.address += sequence.minimum_instruction_length *
((registers.op_index + operation_advance) / sequence.maximum_operations_per_instruction)
((registers.op_index + operation_advance) // sequence.maximum_operations_per_instruction)
registers.op_index = (registers.op_index + operation_advance) % sequence.maximum_operations_per_instruction
end
end
Expand All @@ -281,7 +281,7 @@ module Debug
if opcode >= sequence.opcode_base
# special opcode
adjusted_opcode = opcode - sequence.opcode_base
operation_advance = adjusted_opcode / sequence.line_range
operation_advance = adjusted_opcode // sequence.line_range
increment_address_and_op_index(operation_advance)
registers.line &+= sequence.line_base + (adjusted_opcode % sequence.line_range)
register_to_matrix(sequence, registers)
Expand Down Expand Up @@ -336,7 +336,7 @@ module Debug
registers.basic_block = true
when LNS::ConstAddPc
adjusted_opcode = 255 - sequence.opcode_base
operation_advance = adjusted_opcode / sequence.line_range
operation_advance = adjusted_opcode // sequence.line_range
increment_address_and_op_index(operation_advance)
when LNS::FixedAdvancePc
registers.address += @io.read_bytes(UInt16).not_nil!
Expand Down
6 changes: 3 additions & 3 deletions src/deque.cr
Expand Up @@ -224,7 +224,7 @@ class Deque(T)
rindex -= @capacity if rindex >= @capacity
value = @buffer[rindex]

if index > @size / 2
if index > @size // 2
# Move following items to the left, starting with the first one
# [56-01234] -> [6x-01235]
dst = rindex
Expand Down Expand Up @@ -296,7 +296,7 @@ class Deque(T)
rindex = @start + index
rindex -= @capacity if rindex >= @capacity

if index > @size / 2
if index > @size // 2
# Move following items to the right, starting with the last one
# [56-01234] -> [4560123^]
dst = @start + @size
Expand Down Expand Up @@ -421,7 +421,7 @@ class Deque(T)
@start = (@start + n) % @capacity
else
# Turn *n* into an equivalent index in range -size/2 .. size/2
half = @size / 2
half = @size // 2
if n.abs >= half
n = (n + half) % @size - half
end
Expand Down
2 changes: 1 addition & 1 deletion src/fiber/stack_pool.cr
Expand Up @@ -9,7 +9,7 @@ class Fiber

# Removes and frees at most *count* stacks from the top of the pool,
# returning memory to the operating system.
def collect(count = lazy_size / 2)
def collect(count = lazy_size // 2)
count.times do
if stack = @deque.shift?
LibC.munmap(stack, STACK_SIZE)
Expand Down
2 changes: 1 addition & 1 deletion src/float/printer/cached_powers.cr
Expand Up @@ -157,7 +157,7 @@ module Float::Printer::CachedPowers
min_exp = MIN_TARGET_EXP - (exp + DiyFP::SIGNIFICAND_SIZE)
max_exp = MAX_TARGET_EXP - (exp + DiyFP::SIGNIFICAND_SIZE)
k = ((min_exp + DiyFP::SIGNIFICAND_SIZE - 1) * D_1_LOG2_10).ceil
index = ((CACHED_POWER_OFFSET + k.to_i - 1) / CACHED_EXP_STEP) + 1
index = ((CACHED_POWER_OFFSET + k.to_i - 1) // CACHED_EXP_STEP) + 1
pow = PowCache[index]
return DiyFP.new(pow.significand, pow.binary_exp), pow.decimal_exp.to_i
end
Expand Down
4 changes: 2 additions & 2 deletions src/float/printer/grisu3.cr
Expand Up @@ -251,7 +251,7 @@ module Float::Printer::Grisu3
# with the divisor exponent + 1. And the divisor is the biggest power of ten
# that is smaller than integrals.
while kappa > 0
digit = integrals / divisor
digit = integrals // divisor
# pp [digit, kappa]
buffer[length] = 48_u8 + digit
length += 1
Expand All @@ -271,7 +271,7 @@ module Float::Printer::Grisu3
return weeded, kappa, length
end

divisor /= 10
divisor //= 10
end

# The integrals have been generated. We are at the point of the decimal
Expand Down
4 changes: 2 additions & 2 deletions src/humanize.cr
Expand Up @@ -76,14 +76,14 @@ struct Number
# Number.si_prefix(3) # => 'k'
# ```
def self.si_prefix(magnitude : Int, prefixes = SI_PREFIXES) : Char?
index = (magnitude / 3)
index = (magnitude // 3)
prefixes = prefixes[magnitude < 0 ? 0 : 1]
prefixes[index.clamp((-prefixes.size + 1)..(prefixes.size - 1))]
end

# :nodoc:
def self.prefix_index(i, group = 3)
((i - (i > 0 ? 1 : 0)) / group) * group
((i - (i > 0 ? 1 : 0)) // group) * group
end

# Pretty prints this number as a `String` in a human-readable format.
Expand Down

0 comments on commit 1c2b853

Please sign in to comment.