remove div and add div10

general division is for another day, the 10 version is manageable
also same code produces mod10
wip
This commit is contained in:
Torsten Ruger
2015-11-12 20:03:57 +02:00
parent a5afca10f6
commit 5c862111b9
6 changed files with 31 additions and 15 deletions

View File

@ -13,7 +13,7 @@ class Integer < Value
int num = as_char()
str = str.push_char( num )
else
int rest = self / 10
int rest = self.div10()
str = rest.as_string( str )
rest = rest * 10
rest = self - rest
@ -33,14 +33,7 @@ class Integer < Value
return self
end
int div( Integer by)
int ret = self / by
return ret
end
int mod(Integer by)
int base = self / by
base = base * by
return self - base
int mod4()
return self & 3
end
end

View File

@ -2,7 +2,7 @@ class Word < Object
int char_at(int index)
int word_index = index - 1
word_index = word_index / 4
word_index = word_index >> 2
word_index = word_index + 3
int rest = index - 1
rest = rest.mod(4)
@ -23,7 +23,7 @@ class Word < Object
self.set_length(index)
int word_index = index - 1
word_index = word_index / 4
word_index = word_index >> 2
word_index = word_index + 3
int rest = index - 1