89 lines
1.3 KiB
Plaintext
89 lines
1.3 KiB
Plaintext
class Integer < Value
|
|
|
|
int as_char()
|
|
if_plus( self - 9)
|
|
return 32
|
|
else
|
|
return 48 + self
|
|
end
|
|
end
|
|
|
|
|
|
|
|
int div10_typed()
|
|
int tmp = self >> 1
|
|
int q = self >> 2
|
|
q = q + tmp
|
|
tmp = q >> 4
|
|
q = q + tmp
|
|
tmp = q >> 8
|
|
q = q + tmp
|
|
tmp = q >> 16
|
|
q = q + tmp
|
|
q = q >> 3
|
|
int r = q * 10
|
|
r = self - r
|
|
r = r + 6
|
|
r = r >> 4
|
|
return q + r
|
|
end
|
|
|
|
Word as_string(Word str)
|
|
if_minus( self - 10 )
|
|
int num = as_char()
|
|
str = str.push_char( num )
|
|
else
|
|
int rest = self.div10()
|
|
str = rest.as_string( str )
|
|
rest = rest * 10
|
|
rest = self - rest
|
|
str = rest.as_string(str)
|
|
end
|
|
return str
|
|
end
|
|
|
|
Word to_s()
|
|
Word start = " "
|
|
start.set_length(0)
|
|
return as_string( start )
|
|
end
|
|
|
|
int puti()
|
|
Word str = self.to_s()
|
|
str.putstring()
|
|
return self
|
|
end
|
|
|
|
int mod4()
|
|
return self & 3
|
|
end
|
|
|
|
int fibr( )
|
|
if_plus( self - 2 )
|
|
int tmp
|
|
tmp = self - 1
|
|
int a = tmp.fibr( )
|
|
tmp = self - 2
|
|
int b = tmp.fibr( )
|
|
return a + b
|
|
else
|
|
return self
|
|
end
|
|
end
|
|
|
|
int fibw( )
|
|
int result = 1
|
|
int a = 0
|
|
int b = 1
|
|
int i = 2
|
|
while_plus( self - i )
|
|
result = a + b
|
|
a = b
|
|
b = result
|
|
i = i + 1
|
|
end
|
|
return result
|
|
end
|
|
|
|
end
|