10 months ago | Paul Boddie | file changeset files shortlog | Permit the replacement of floating-point values in locally-referenced objects. To achieve this, a result target parameter has been introduced in callable signatures alongside the existing context parameter so that references to objects can be propagated to operations that are able to replace the value of such objects. Result target objects are currently supported only for locals and intermediate results in functions and methods, with assignments to locals or the storage of intermediate results involving the copying of any given floating-point objects instead of merely referencing them. Such distinct copies may then be used as result targets when locals or intermediate result locations are subsequently reused. Value replacement avoids the allocation of temporary objects that can quickly dominate execution time in programs repeatedly performing large numbers of floating-point calculations. | value-replacement |
paul@929 | 1 | i = int(123) |
paul@929 | 2 | j = 123 |
paul@929 | 3 | print i, j, i == j # 123 123 True |
paul@929 | 4 | k = 456 |
paul@929 | 5 | print i, k, i == k # 123 456 False |
paul@929 | 6 | h = int(789) |
paul@929 | 7 | print i, h, i == h # 123 789 False |
paul@929 | 8 | print j, h, j == h # 123 789 False |
paul@929 | 9 | |
paul@929 | 10 | try: |
paul@929 | 11 | a = int("a") # should raise an exception |
paul@929 | 12 | except ValueError, exc: |
paul@929 | 13 | print 'int("a") failed:', exc.value |
paul@932 | 14 | |
paul@932 | 15 | try: |
paul@932 | 16 | a = int("!") # should raise an exception |
paul@932 | 17 | except ValueError, exc: |
paul@932 | 18 | print 'int("!") failed:', exc.value |
paul@932 | 19 | |
paul@932 | 20 | a = int("a", 16) |
paul@932 | 21 | b = int("123") |
paul@932 | 22 | print a # 10 |
paul@932 | 23 | print b, i, b == i # 123, 123, True |
paul@932 | 24 | print b, j, b == j # 123, 123, True |
paul@932 | 25 | |
paul@932 | 26 | a_is_int = isinstance(a, int) |
paul@932 | 27 | j_is_int = isinstance(j, int) |
paul@932 | 28 | |
paul@932 | 29 | print a_is_int # True |
paul@932 | 30 | print j_is_int # True |