Ejemplo n.º 1
0
    def init_library(self):
        max = Utils.bin_to_dec("1" + "0" * 8) - 1  # 8 bits
        if self.signed: max = max / 2

        if self.max_num and self.max_num > max:
            raise Exception("%s primitive maximum value is %d" %
                            (self.type, max))
        if self.max_num == None or self.max_num == 0:
            self.max_num = max

        if self.full_range:
            for i in xrange(0, self.max_num + 1):
                if i not in self.library: self.library.append(i)
        else:
            self.library += Utils.integer_boundaries(self.library,
                                                     self.max_num, 0)
            self.library += Utils.integer_boundaries(self.library,
                                                     self.max_num,
                                                     self.max_num)
            for v in [2, 3, 4, 8, 16, 32]:
                self.library += Utils.integer_boundaries(
                    self.library, self.max_num, self.max_num / v)

        negatives = []
        if self.signed:
            for v in self.library:
                negatives.append(-v)
        self.library += negatives
Ejemplo n.º 2
0
    def init_library(self):
        max = Utils.bin_to_dec("1" + "0" * (self.get('size') * 8)) - 1

        if self.full_range:
            for i in xrange(0, max + 1):
                if i not in self.library: self.library.append(i)
        else:
            self.library += Utils.integer_boundaries(self.library, max, 0)
            self.library += Utils.integer_boundaries(self.library, max, max)
            for v in [2, 3, 4, 8, 16, 32]:
                self.library += Utils.integer_boundaries(
                    self.library, max, max / v)