def setf(self, value):
"""store /value/ into a binary format"""
exponentbias = (2**self.components[1])/2 - 1
m,e = math.frexp(value)
# extract components from value
s = math.copysign(1.0, m)
m = abs(m)
# convert to integrals
sf = 1 if s < 0 else 0
exponent = e + exponentbias - 1
m = m*2.0 - 1.0 # remove the implicit bit
mantissa = int(m * (2**self.components[2]))
# store components
result = bitmap.zero
result = bitmap.push( result, bitmap.new(sf,self.components[0]) )
result = bitmap.push( result, bitmap.new(exponent,self.components[1]) )
result = bitmap.push( result, bitmap.new(mantissa,self.components[2]) )
return self.__setvalue__( result[0] )
评论列表
文章目录