Example #1
0
	def make(cls, number, ordinal=False):
		s = ''
		
		if ordinal:
			s += cls.ORDINAL_GLYPH
		
		if number < 0:
			s += cls.NEGATIVE_GLYPH
			number = -number
			
		if number < 10:
			return s + cls.GLYPHS[number]
		
		h = hierarchicize(number, cls.HIERARCHY)
		
		
		
		for i in range(len(h)):
			if h[i] == 0:	# If there are more than one pegs on this row of the abacus ... (otherwise, do nothing)
				continue
			else:
				if cls.HIERARCHY[i] != 1 and h[i] != 1:	# Leave out the 'one' in e.g. 'one ten' if it is obvious
					s += cls.GLYPHS[h[i]]
				if cls.HIERARCHY[i] != 1:
					s += cls.GLYPHS[cls.HIERARCHY[i]]
		return s
Example #2
0
	def _recurse(cls, number, ordinal, eon=True):
		"""
		eon = End Of Number; due to recursion we have to tell the function whether to add the end-of-number symbol
		"""
		
		h = hierarchicize(number, [1000,100,10,1])
		
		s = u''

		"""
		The number of thousands X is indicated simply by the number X.
		I'm a bit confused as to whether this simple recursion is really how
		really big numbers are represented though... it must be confusing!
		In the Greek numeral system, is the prefix ONLY added before the thousands?
		And what happens after a million?
		"""
		if h[0] > 0:
			s += cls._recurse(h[0], ordinal, False)
		if h[1] > 0:
			s += cls.NUMERALS[h[1] * 100]
		if h[2] > 0:
			s += cls.NUMERALS[h[2] * 10]
		if h[3] > 0:
			if not eon:
				s += cls.BIG_NUMBER_PREFIX
			s += cls.NUMERALS[h[3]]
		
		if eon:
			s += cls.END_OF_NUMBER_SUFFIX
		
		# I'm confused as to which order we should return the string in: Hebrew is an RTL language, and yet UTF seems to autoformat ... ???  I'm going to leave it as-is for now; you can reverse on your own
		return s
Example #3
0
	def make(cls, number, ordinal=False):
		# Note that roman ordinal numbers are represented in the same way as cardinal.
		if number == 0:
			return u'nulla'
		
		thousands, hundreds, tens, ones = hierarchicize(number, [1000,100,10,1])
		
		string = ''
		
		for i in range(thousands):
			string += u'M'
			
		if hundreds > 0: 
			string += [u'C', u'CC', u'CCC', u'CD', u'D', u'DC', u'DCC', u'DCCC', u'CM'][hundreds-1]
		if tens > 0:
			string += [u'X', u'XX', u'XXX', u'XL', u'L', u'LX', u'LXX', u'LXXX', u'XC'][tens-1]
		if ones > 0:
			string += [u'I', u'II', u'III', u'IV', u'V', u'VI', u'VII', u'VIII', u'IX'][ones-1]
		
		return string
Example #4
0

# Test int_to_base_array()
for test in [
	(	(255,10),		[2,5,5]				),
	(	(256,10),		[2,5,6]				),
	(	(255,2),		[1,1,1,1,1,1,1,1]	),
	]:
	assert int_to_base_array(*test[0]) == test[1]


# Test split()
for test in [
	(	(1,1),			(1,0)		),
	(	(10,1),			(10,0)		),
	(	(0,1),			(0,0)		),
	(	(1.5,0.5),		(3,0)		),
	(	(1.5,1),		(1,0.5)		),
	(	(15,10),		(1,5)		),
	]:
	assert split(*test[0]) == test[1]

# Test hierarchicize()
for test in [
	(	(100,[1]),			[100]		),
	(	(100,[1,1]),		[100,0]		),
	(	(100,[100,1]),		[1,0]		),
	(	(1000,[360,12]),	[2,23]		),
	]:
	assert hierarchicize(*test[0]) == test[1]