Ticket #1616: PCA-patch-008.patch
File PCA-patch-008.patch, 6.1 KB (added by Paul C. Anagnostopoulos, 11 years ago) |
---|
-
src/pmc/boolean.pmc
99 99 VTABLE void set_string_native(STRING *value) { 100 100 SELF.set_bool(Parrot_str_boolean(INTERP, value)); 101 101 } 102 103 /* 104 105 =item C<PMC *neg(PMC *dest)> 106 107 =item C<void i_neg()> 108 109 Set C<dest> to the ''negated'' value of C<SELF>. The negative of a 110 boolean value is the identical value. 111 112 =cut 113 114 */ 115 116 VTABLE PMC *neg(PMC *dest) { 117 dest = Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF), 118 SELF.get_bool()); 119 return dest; 120 } 121 122 VTABLE void i_neg() { 123 } 102 124 } 103 125 104 126 /* -
src/pmc/integer.pmc
257 257 258 258 =item C<void set_integer_native(INTVAL value)> 259 259 260 Sets the value of the integer to the value of the C<Integer>C<*value>.260 Sets the value of the integer to the value of the native integer C<*value>. 261 261 262 262 =cut 263 263 … … 987 987 988 988 /* 989 989 990 =item C<PMC *neg(PMC *dest)> 991 992 =item C<void i_neg()> 993 994 Set C<dest> to the negated value of C<SELF>. If the value of C<SELF> 995 is the minimum integer, a BigInt is created. 996 997 =cut 998 999 */ 1000 1001 VTABLE PMC *neg(PMC *dest) { 1002 const INTVAL a = SELF.get_integer(); 1003 1004 if (a != PARROT_INTVAL_MIN) 1005 return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF), 1006 -a); 1007 else { 1008 PMC *promoted; 1009 maybe_throw_overflow_error(INTERP); 1010 promoted = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt, 0); 1011 return VTABLE_subtract_int(INTERP, promoted, a, promoted); 1012 } 1013 } 1014 1015 VTABLE void i_neg() { 1016 const INTVAL a = SELF.get_integer(); 1017 1018 if (a != PARROT_INTVAL_MIN) 1019 VTABLE_set_integer_native(INTERP, SELF, -a); 1020 else { 1021 maybe_throw_overflow_error(INTERP); 1022 SELF = upgrade_self_to_bignum(INTERP, SELF); 1023 VTABLE_set_integer_native(INTERP, SELF, 0); 1024 VTABLE_i_subtract_int(INTERP, SELF, a); 1025 } 1026 } 1027 1028 /* 1029 990 1030 =item C<INTVAL is_equal(PMC *value)> 991 1031 992 1032 The C<==> operation. … … 1158 1198 1159 1199 =item C<void absolute()> 1160 1200 1161 Sets C<dest> to the absolute value of SELF. 1201 Sets C<dest> to the absolute value of C<SELF>. If the value of C<SELF> 1202 is the minimum integer, a BigInt is created. 1162 1203 1163 1204 =cut 1164 1205 1165 1206 */ 1166 1207 1167 1208 VTABLE PMC *absolute(PMC *dest) { 1168 const INTVAL a = abs(SELF.get_integer());1209 const INTVAL a = SELF.get_integer(); 1169 1210 1170 /* TT # 1245 overflow for -maxint */ 1171 return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF), a); 1211 if (a != PARROT_INTVAL_MIN) 1212 return Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF), 1213 abs(a)); 1214 else { 1215 PMC *promoted; 1216 maybe_throw_overflow_error(INTERP); 1217 promoted = Parrot_pmc_new_init_int(INTERP, enum_class_BigInt, a); 1218 return VTABLE_neg(INTERP, promoted, dest); 1219 } 1172 1220 } 1173 1221 1174 1222 1175 1223 VTABLE void i_absolute() { 1176 const INTVAL a = abs(SELF.get_integer()); 1177 VTABLE_set_integer_native(INTERP, SELF, a); 1224 const INTVAL a = SELF.get_integer(); 1225 1226 if (a != PARROT_INTVAL_MIN) 1227 VTABLE_set_integer_native(INTERP, SELF, abs(a)); 1228 else { 1229 maybe_throw_overflow_error(INTERP); 1230 SELF = upgrade_self_to_bignum(INTERP, SELF); 1231 return VTABLE_i_neg(INTERP, SELF); 1232 } 1178 1233 } 1179 1234 1180 1235 -
t/pmc/bigint.t
20 20 21 21 .include 'test_more.pir' 22 22 23 plan(3 4)23 plan(32) 24 24 check_libgmp_good() 25 25 26 26 set_and_get() … … 28 28 subtraction() 29 29 multiplication() 30 30 division() 31 division_by_zero()32 31 negation() 32 negate_min_integer() 33 33 absolute_value() 34 absolute_min_integer() 34 35 overflow_coercion() 35 36 interface() 36 37 boolean() … … 504 505 ok($I1, 'negation') 505 506 .end 506 507 508 .loadlib 'sys_ops' 509 .include 'sysinfo.pasm' 510 511 .sub negate_min_integer 512 .local int max 513 .local int min 514 .local pmc max_1 515 .local pmc neg_min 516 max = sysinfo .SYSINFO_PARROT_INTMAX 517 min = sysinfo .SYSINFO_PARROT_INTMIN 518 max_1 = box max 519 inc max_1 520 neg_min = box min 521 neg neg_min # Use 1-operand form of neg. 522 is(neg_min, max_1, 'negate minimum native integer') 523 .end 524 507 525 .sub absolute_value 508 526 $P0 = new ['BigInt'] 509 527 $P0 = '-1230000000000000000000' … … 522 540 is($S0,'1230000000000000000000','... and in-place works too') 523 541 .end 524 542 543 .sub absolute_min_integer 544 .local int max 545 .local int min 546 .local pmc max_1 547 .local pmc neg_min 548 .local pmc result 549 max = sysinfo .SYSINFO_PARROT_INTMAX 550 min = sysinfo .SYSINFO_PARROT_INTMIN 551 max_1 = box max 552 inc max_1 553 neg_min = box min 554 result = abs neg_min # Use 2-operand form of abs. 555 is(result, max_1, 'absolute minimum native integer') 556 .end 557 525 558 .sub overflow_coercion 526 559 # check libgmp included in Parrot build 527 560 $P0 = getinterp … … 745 778 ne $S0, $S6, k25 746 779 inc $I1 747 780 k25: 748 todo( $I1, 'integer negation of MinInt converts MaxInt+1 to BigInt', 'TT #1616')781 ok($I1, 'integer negation of MinInt converts to BigInt') 749 782 750 783 $I1 = 0 751 784 $P0 = new ['Integer'] … … 760 793 ne $S0, $S6, k27 761 794 inc $I1 762 795 k27: 763 todo( $I1, 'integer absolute-value of MinInt converts MaxInt+1 to BigInt', 'TT #1616')796 ok($I1, 'integer abs(MinInt) converts to BigInt') 764 797 765 798 $P0 = new ['Integer'] 766 799 $P0 = $I3