# Path: bigrig/interpreter/exceptions.py
# class ESTypeError(ESError):
#     """
#     Invalid type.
#     """
#     pass
# 
# class ESSyntaxError(ESError):
#     """
#     Invalid syntax.
#     """
#     pass
# 
# Path: bigrig/interpreter/literals.py
# class NumberLiteralParser(LiteralParser):
#     """
#     Parse integer and floating point numbers.
#     """
#     def __init__(self, string, allow_octal=True):
#         super(NumberLiteralParser, self).__init__(string)
#         self.allow_octal = allow_octal
# 
#     def parse_hex_literal(self):
#         digits = []
#         char = self.peek()
#         if char != u'0':
#             raise ESSyntaxError('Invalid number literal')
#         self.advance()
#         char = self.peek()
#         if char not in (u'x', u'X'):
#             raise ESSyntaxError('Invalid number literal')
#         self.advance()
#         char = self.peek()
#         while char in HEX_DIGITS:
#             digits.append(char)
#             self.advance()
#             char = self.peek()
#         if char != u'':
#             raise ESSyntaxError('Invalid number literal') 
#         if not digits:
#             raise ESSyntaxError('Invalid number literal')
#         return int(u''.join(digits), 16)
# 
#     def parse_octal_literal(self):
#         digits = []
#         char = self.peek()
#         if char != u'0':
#             raise ESSyntaxError('Invalid number literal')
#         self.advance()
#         char = self.peek()
#         while char in OCTAL_DIGITS:
#             digits.append(char)
#             self.advance()
#             char = self.peek()
#         if char != u'':
#             if char in DECIMAL_DIGITS:
#                 return self.parse_decimal_literal(digits)
#             raise ESSyntaxError('Invalid number literal')
#         return int(u''.join(digits), 8)
# 
#     def parse_decimal_literal(self, digits=None):
#         if digits is None:
#             digits = []
#         decimal_digits = []
#         power_sign = 1
#         power_digits = []
#         while self.peek() in DECIMAL_DIGITS:
#             digits.append(self.peek())
#             self.advance()
#         if self.peek() == u'.':
#             self.advance()
#             while self.peek() in DECIMAL_DIGITS:
#                 decimal_digits.append(self.peek())
#                 self.advance()
#         if self.peek() in (u'e', u'E'):
#             power_sign = 1
#             self.advance()
#             if self.peek() == u'-':
#                 power_sign = -1
#                 self.advance()
#             elif self.peek() == u'+':
#                 self.advance()
#             if self.peek() not in DECIMAL_DIGITS:
#                 raise ESSyntaxError('Invalid number literal')
#             while self.peek() in DECIMAL_DIGITS:
#                 power_digits.append(self.peek())
#                 self.advance()
#         if self.peek() != u'':
#             raise ESSyntaxError('Invalid number literal')
#         if digits:
#             integral = int(u''.join(digits))
#             if decimal_digits and power_digits:
#                 power = power_sign * int(u''.join(power_digits))
#                 decimal = int(u''.join(decimal_digits)) * (10 ** (power-len(decimal_digits)))
#                 return integral * (10 ** power) + decimal
#             elif decimal_digits:
#                 return integral + (int(u''.join(decimal_digits)) * (10 ** -len(decimal_digits)))
#             elif power_digits:
#                 power = power_sign * int(u''.join(power_digits))
#                 if power < 0 and digits[power:] and digits[:power] and int(u''.join(digits[power:])) == 0:
#                     return int(u''.join(digits[:power]))
#                 return integral * (10 ** power)
#             return integral
#         elif decimal_digits:
#             if power_digits:
#                 power = power_sign * int(u''.join(power_digits))
#                 return int(u''.join(decimal_digits)) * (10 ** (power - len(decimal_digits)))
#             return int(u''.join(decimal_digits)) * (10 ** -len(decimal_digits))
#         return NaN
# 
#     def parse(self):
#         # This doesn't follow the spec exactly in that it allows leading 0 digits
#         char = self.peek()
#         if char == u'0':
#             lookahead = self.peek(2)
#             if lookahead in (u'x', u'X'):
#                 return self.parse_hex_literal()
#         while char == u'0':
#             if lookahead in OCTAL_DIGITS:
#                 if not self.allow_octal:
#                     raise ESSyntaxError('Invalid number literal')
#                 return self.parse_octal_literal()
#             elif lookahead == u'':
#                 return 0
#             elif lookahead in (u'.', u'e', u'E'):
#                 break
#             elif lookahead != '0':
#                 raise ESSyntaxError('Invalid number literal')
#             self.advance()
#             char = self.peek()
#             lookahead = self.peek(2)
#         return self.parse_decimal_literal()


import math
from itertools import izip_longest
from .exceptions import ESTypeError, ESSyntaxError
from .literals import NumberLiteralParser
        primitive_type = get_primitive_type(value)
        if primitive_type is Undefined:
            return NaN
        elif primitive_type is Null:
            return +0
        elif primitive_type is ObjectType:
            primitive_value = self.to_primitive(value, preferred_type='Number')
            return self.to_number(primitive_value)
        primitive_value = self.to_primitive(value)
        if primitive_type is NumberType:
            return primitive_value
        elif primitive_type is BooleanType:
            return int(primitive_value)
        elif primitive_type is StringType:
            try:
                value = primitive_value.strip()
                if not value:
                    return 0
                sign = 1
                has_sign = False
                if value[0] == u'-':
                    sign = -1
                    value = value[1:]
                    has_sign = True
                elif value[0] == u'+':
                    value = value[1:]
                    has_sign = True
                if value == u'Infinity':
                    return sign * inf
                if has_sign:

# Path: bigrig/interpreter/exceptions.py
# class ESTypeError(ESError):
#     """
#     Invalid type.
#     """
#     pass
# 
# class ESSyntaxError(ESError):
#     """
#     Invalid syntax.
#     """
#     pass
# 
# Path: bigrig/interpreter/literals.py
# class NumberLiteralParser(LiteralParser):
#     """
#     Parse integer and floating point numbers.
#     """
#     def __init__(self, string, allow_octal=True):
#         super(NumberLiteralParser, self).__init__(string)
#         self.allow_octal = allow_octal
# 
#     def parse_hex_literal(self):
#         digits = []
#         char = self.peek()
#         if char != u'0':
#             raise ESSyntaxError('Invalid number literal')
#         self.advance()
#         char = self.peek()
#         if char not in (u'x', u'X'):
#             raise ESSyntaxError('Invalid number literal')
#         self.advance()
#         char = self.peek()
#         while char in HEX_DIGITS:
#             digits.append(char)
#             self.advance()
#             char = self.peek()
#         if char != u'':
#             raise ESSyntaxError('Invalid number literal') 
#         if not digits:
#             raise ESSyntaxError('Invalid number literal')
#         return int(u''.join(digits), 16)
# 
#     def parse_octal_literal(self):
#         digits = []
#         char = self.peek()
#         if char != u'0':
#             raise ESSyntaxError('Invalid number literal')
#         self.advance()
#         char = self.peek()
#         while char in OCTAL_DIGITS:
#             digits.append(char)
#             self.advance()
#             char = self.peek()
#         if char != u'':
#             if char in DECIMAL_DIGITS:
#                 return self.parse_decimal_literal(digits)
#             raise ESSyntaxError('Invalid number literal')
#         return int(u''.join(digits), 8)
# 
#     def parse_decimal_literal(self, digits=None):
#         if digits is None:
#             digits = []
#         decimal_digits = []
#         power_sign = 1
#         power_digits = []
#         while self.peek() in DECIMAL_DIGITS:
#             digits.append(self.peek())
#             self.advance()
#         if self.peek() == u'.':
#             self.advance()
#             while self.peek() in DECIMAL_DIGITS:
#                 decimal_digits.append(self.peek())
#                 self.advance()
#         if self.peek() in (u'e', u'E'):
#             power_sign = 1
#             self.advance()
#             if self.peek() == u'-':
#                 power_sign = -1
#                 self.advance()
#             elif self.peek() == u'+':
#                 self.advance()
#             if self.peek() not in DECIMAL_DIGITS:
#                 raise ESSyntaxError('Invalid number literal')
#             while self.peek() in DECIMAL_DIGITS:
#                 power_digits.append(self.peek())
#                 self.advance()
#         if self.peek() != u'':
#             raise ESSyntaxError('Invalid number literal')
#         if digits:
#             integral = int(u''.join(digits))
#             if decimal_digits and power_digits:
#                 power = power_sign * int(u''.join(power_digits))
#                 decimal = int(u''.join(decimal_digits)) * (10 ** (power-len(decimal_digits)))
#                 return integral * (10 ** power) + decimal
#             elif decimal_digits:
#                 return integral + (int(u''.join(decimal_digits)) * (10 ** -len(decimal_digits)))
#             elif power_digits:
#                 power = power_sign * int(u''.join(power_digits))
#                 if power < 0 and digits[power:] and digits[:power] and int(u''.join(digits[power:])) == 0:
#                     return int(u''.join(digits[:power]))
#                 return integral * (10 ** power)
#             return integral
#         elif decimal_digits:
#             if power_digits:
#                 power = power_sign * int(u''.join(power_digits))
#                 return int(u''.join(decimal_digits)) * (10 ** (power - len(decimal_digits)))
#             return int(u''.join(decimal_digits)) * (10 ** -len(decimal_digits))
#         return NaN
# 
#     def parse(self):
#         # This doesn't follow the spec exactly in that it allows leading 0 digits
#         char = self.peek()
#         if char == u'0':
#             lookahead = self.peek(2)
#             if lookahead in (u'x', u'X'):
#                 return self.parse_hex_literal()
#         while char == u'0':
#             if lookahead in OCTAL_DIGITS:
#                 if not self.allow_octal:
#                     raise ESSyntaxError('Invalid number literal')
#                 return self.parse_octal_literal()
#             elif lookahead == u'':
#                 return 0
#             elif lookahead in (u'.', u'e', u'E'):
#                 break
#             elif lookahead != '0':
#                 raise ESSyntaxError('Invalid number literal')
#             self.advance()
#             char = self.peek()
#             lookahead = self.peek(2)
#         return self.parse_decimal_literal()


# Path: bigrig/interpreter/types.py
import math
from itertools import izip_longest
from .exceptions import ESTypeError, ESSyntaxError
from .literals import NumberLiteralParser

        primitive_type = get_primitive_type(value)
        if primitive_type is Undefined:
            return NaN
        elif primitive_type is Null:
            return +0
        elif primitive_type is ObjectType:
            primitive_value = self.to_primitive(value, preferred_type='Number')
            return self.to_number(primitive_value)
        primitive_value = self.to_primitive(value)
        if primitive_type is NumberType:
            return primitive_value
        elif primitive_type is BooleanType:
            return int(primitive_value)
        elif primitive_type is StringType:
            try:
                value = primitive_value.strip()
                if not value:
                    return 0
                sign = 1
                has_sign = False
                if value[0] == u'-':
                    sign = -1
                    value = value[1:]
                    has_sign = True
                elif value[0] == u'+':
                    value = value[1:]
                    has_sign = True
                if value == u'Infinity':
                    return sign * inf
                if has_sign:

                    return sign * NumberLiteralParser(value).parse_decimal_literal()