Number of digits of an integer in base b (plus one if negative)

assert 123.digit_count(10) == 3
assert 123.digit_count(2) == 7

Property definitions

core $ Int :: digit_count
	# Number of digits of an integer in base `b` (plus one if negative)
	#
	#     assert 123.digit_count(10) == 3
	#     assert 123.digit_count(2) == 7 # 1111011 in binary
	fun digit_count(b: Int): Int
	do
		if b == 10 then return digit_count_base_10
		var d: Int # number of digits
		var n: Int # current number
		# Sign
		if self < 0 then
			d = 1
			n = - self
		else if self == 0 then
			return 1
		else
			d = 0
			n = self
		end
		# count digits
		while n > 0 do
			d += 1
			n = n / b	# euclidian division /
		end
		return d
	end
lib/core/kernel.nit:810,2--835,4