9 months ago | Paul Boddie | raw annotate files changeset graph | 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 |
1 i = int(123) 2 j = 123 3 print i, j, i == j # 123 123 True 4 k = 456 5 print i, k, i == k # 123 456 False 6 h = int(789) 7 print i, h, i == h # 123 789 False 8 print j, h, j == h # 123 789 False 9 10 try: 11 a = int("a") # should raise an exception 12 except ValueError, exc: 13 print 'int("a") failed:', exc.value 14 15 try: 16 a = int("!") # should raise an exception 17 except ValueError, exc: 18 print 'int("!") failed:', exc.value 19 20 a = int("a", 16) 21 b = int("123") 22 print a # 10 23 print b, i, b == i # 123, 123, True 24 print b, j, b == j # 123, 123, True 25 26 a_is_int = isinstance(a, int) 27 j_is_int = isinstance(j, int) 28 29 print a_is_int # True 30 print j_is_int # True