Ticket #313: tt313-add-neg_0.patch
File tt313-add-neg_0.patch, 18.1 KB (added by rurban, 13 years ago) |
---|
-
lib/Parrot/Configure/Step/List.pm
old new 50 50 auto::memalign 51 51 auto::signal 52 52 auto::socklen_t 53 auto::neg_0 53 54 auto::env 54 55 auto::gmp 55 56 auto::readline -
t/op/arithmetics.t
old new 33 33 pasm_output_is( <<'CODE', <<OUTPUT, "take the negative of a native integer" ); 34 34 set I0, 0 35 35 neg I0 36 print I0 37 print "\n" 36 say I0 38 37 set I0, 1234567890 39 38 neg I0 40 print I0 41 print "\n" 39 say I0 42 40 set I0, -1234567890 43 41 neg I0 44 print I0 45 print "\n" 42 say I0 46 43 set I0, 0 47 44 set I1, 0 48 45 neg I1, I0 49 print I1 50 print "\n" 46 say I1 51 47 set I0, 1234567890 52 48 neg I1, I0 53 print I1 54 print "\n" 49 say I1 55 50 set I0, -1234567890 56 51 neg I1, I0 57 print I1 58 print "\n" 52 say I1 59 53 end 60 54 CODE 61 55 0 … … 69 63 pasm_output_is( <<'CODE', <<OUTPUT, "take the absolute of a native integer" ); 70 64 set I0, 0 71 65 abs I0 72 print I0 73 print "\n" 66 say I0 74 67 set I0, 1234567890 75 68 abs I0 76 print I0 77 print "\n" 69 say I0 78 70 set I0, -1234567890 79 71 abs I0 80 print I0 81 print "\n" 72 say I0 82 73 set I0, 0 83 74 set I1, 0 84 75 abs I1, I0 85 print I1 86 print "\n" 76 say I1 87 77 set I0, 1234567890 88 78 abs I1, I0 89 print I1 90 print "\n" 79 say I1 91 80 set I0, -1234567890 92 81 abs I1, I0 93 print I1 94 print "\n" 82 say I1 95 83 end 96 84 CODE 97 85 0 … … 109 97 set I0, 4000 110 98 set I1, -123 111 99 add I2, I0, I1 112 print I2 113 print "\n" 100 say I2 114 101 add I0, I0, I1 115 print I0 116 print "\n" 102 say I0 117 103 end 118 104 CODE 119 105 3877 … … 124 110 set I0, 4000 125 111 set I1, -123 126 112 sub I2, I0, I1 127 print I2 128 print "\n" 113 say I2 129 114 sub I0, I0, I1 130 print I0 131 print "\n" 115 say I0 132 116 end 133 117 CODE 134 118 4123 … … 139 123 set I0, 4000 140 124 set I1, -123 141 125 mul I2, I0, I1 142 print I2 143 print "\n" 126 say I2 144 127 mul I0, I0, I1 145 print I0 146 print "\n" 128 say I0 147 129 end 148 130 CODE 149 131 -492000 … … 154 136 set I0, 4000 155 137 set I1, -123 156 138 div I2, I0, I1 157 print I2 158 print "\n" 139 say I2 159 140 div I0, I0, I1 160 print I0 161 print "\n" 141 say I0 162 142 end 163 143 CODE 164 144 -32 … … 177 157 pasm_output_is( <<'CODE', <<OUTPUT, 'negate -0.0', @todo ); 178 158 set N0, 0 179 159 neg N0 180 print N0 181 print "\n" 160 say N0 182 161 set N0, -0.0 183 162 neg N0 184 print N0 185 print "\n" 163 say N0 186 164 set N0, -0.0 187 165 neg N1, N0 188 print N1 189 print "\n" 166 say N1 167 set N0, 0 168 set N1, 1 169 neg N1, N0 170 say N1 171 end 190 172 CODE 191 173 -0 192 174 0 193 -0194 175 0 176 -0 195 177 OUTPUT 196 178 197 179 } … … 204 186 pasm_output_is( <<'CODE', <<OUTPUT, 'negate a native number' ); 205 187 set N0, 123.4567890 206 188 neg N0 207 print N0 208 print "\n" 189 say N0 209 190 set N0, -123.4567890 210 191 neg N0 211 print N0 212 print "\n" 213 set N0, 0 214 set N1, 1 215 neg N1, N0 216 print N1 217 print "\n" 192 say N0 218 193 set N0, 123.4567890 219 194 neg N1, N0 220 print N1 221 print "\n" 195 say N1 222 196 set N0, -123.4567890 223 197 neg N1, N0 224 print N1 225 print "\n" 198 say N1 226 199 end 227 200 CODE 228 201 -123.456789 229 202 123.456789 230 0231 203 -123.456789 232 204 123.456789 233 205 OUTPUT … … 235 207 pasm_output_is( <<'CODE', <<OUTPUT, "take the absolute of a native number" ); 236 208 set N0, 0 237 209 abs N0 238 print N0 239 print "\n" 210 say N0 240 211 set N0, -0.0 241 212 abs N0 242 print N0 243 print "\n" 213 say N0 244 214 set N0, 123.45678901 245 215 abs N0 246 print N0 247 print "\n" 216 say N0 248 217 set N0, -123.45678901 249 218 abs N0 250 print N0 251 print "\n" 219 say N0 252 220 set N0, 0 253 221 set N1, 1 254 222 abs N1, N0 255 print N1 256 print "\n" 223 say N1 257 224 set N0, 0.0 258 225 set N1, 1 259 226 abs N1, N0 260 print N1 261 print "\n" 227 say N1 262 228 set N0, 123.45678901 263 229 set N1, 1 264 230 abs N1, N0 265 print N1 266 print "\n" 231 say N1 267 232 set N0, -123.45678901 268 233 set N1, 1 269 234 abs N1, N0 270 print N1 271 print "\n" 235 say N1 272 236 end 273 237 CODE 274 238 0 … … 284 248 pasm_output_is( <<'CODE', <<OUTPUT, "ceil of a native number" ); 285 249 set N0, 0 286 250 ceil N0 287 print N0 288 print "\n" 251 say N0 289 252 set N0, 123.45678901 290 253 ceil N0 291 print N0 292 print "\n" 254 say N0 293 255 set N0, -123.45678901 294 256 ceil N0 295 print N0 296 print "\n" 257 say N0 297 258 set N0, 0 298 259 set N1, 1 299 260 ceil N1, N0 300 print N1 301 print "\n" 261 say N1 302 262 set N0, 0.0 303 263 set N1, 1 304 264 ceil N1, N0 305 print N1 306 print "\n" 265 say N1 307 266 set N0, 123.45678901 308 267 set N1, 1 309 268 ceil N1, N0 310 print N1 311 print "\n" 269 say N1 312 270 set N0, -123.45678901 313 271 set N1, 1 314 272 ceil N1, N0 315 print N1 316 print "\n" 273 say N1 317 274 set N0, 0 318 275 set I1, 1 319 276 ceil I1, N0 320 print I1 321 print "\n" 277 say I1 322 278 set N0, 0.0 323 279 set I1, 1 324 280 ceil I1, N0 325 print I1 326 print "\n" 281 say I1 327 282 set N0, 123.45678901 328 283 set I1, 1 329 284 ceil I1, N0 330 print I1 331 print "\n" 285 say I1 332 286 set N0, -123.45678901 333 287 set I1, 1 334 288 ceil I1, N0 335 print I1 336 print "\n" 289 say I1 337 290 end 338 291 CODE 339 292 0 … … 352 305 pasm_output_is( <<'CODE', <<OUTPUT, "floor of a native number" ); 353 306 set N0, 0 354 307 floor N0 355 print N0 356 print "\n" 308 say N0 357 309 set N0, 123.45678901 358 310 floor N0 359 print N0 360 print "\n" 311 say N0 361 312 set N0, -123.45678901 362 313 floor N0 363 print N0 364 print "\n" 314 say N0 365 315 set N0, 0 366 316 set N1, 1 367 317 floor N1, N0 368 print N1 369 print "\n" 318 say N1 370 319 set N0, 0.0 371 320 set N1, 1 372 321 floor N1, N0 373 print N1 374 print "\n" 322 say N1 375 323 set N0, 123.45678901 376 324 set N1, 1 377 325 floor N1, N0 378 print N1 379 print "\n" 326 say N1 380 327 set N0, -123.45678901 381 328 set N1, 1 382 329 floor N1, N0 383 print N1 384 print "\n" 330 say N1 385 331 set N0, 0 386 332 set I1, 1 387 333 floor I1, N0 388 print I1 389 print "\n" 334 say I1 390 335 set N0, 0.0 391 336 set I1, 1 392 337 floor I1, N0 393 print I1 394 print "\n" 338 say I1 395 339 set N0, 123.45678901 396 340 set I1, 1 397 341 floor I1, N0 398 print I1 399 print "\n" 342 say I1 400 343 set N0, -123.45678901 401 344 set I1, 1 402 345 floor I1, N0 403 print I1 404 print "\n" 346 say I1 405 347 end 406 348 CODE 407 349 0 … … 424 366 set I0, 4000 425 367 set N0, -123.123 426 368 add N1, N0, I0 427 print N1 428 print "\n" 369 say N1 429 370 add N0, N0, I0 430 print N0 431 print "\n" 371 say N0 432 372 add N0, I0 433 print N0 434 print "\n" 373 say N0 435 374 end 436 375 CODE 437 376 3876.877 … … 443 382 set I0, 4000 444 383 set N0, -123.123 445 384 sub N1, N0, I0 446 print N1 447 print "\n" 385 say N1 448 386 sub N0, N0, I0 449 print N0 450 print "\n" 387 say N0 451 388 sub N0, I0 452 print N0 453 print "\n" 389 say N0 454 390 end 455 391 CODE 456 392 -4123.123 … … 462 398 set I0, 4000 463 399 set N0, -123.123 464 400 mul N1, N0, I0 465 print N1 466 print "\n" 401 say N1 467 402 mul N0, N0, I0 468 print N0 469 print "\n" 403 say N0 470 404 mul N0, -2 471 print N0 472 print "\n" 405 say N0 473 406 end 474 407 CODE 475 408 -492492 … … 481 414 set I0, 4000 482 415 set N0, -123.123 483 416 div N1, N0, I0 484 print N1 485 print "\n" 417 say N1 486 418 div N0, N0, I0 487 print N0 488 print "\n" 419 say N0 489 420 div N0, 1 490 print N0 491 print "\n" 421 say N0 492 422 set N0, 100.000 493 423 div N0, 100 494 print N0 495 print "\n" 424 say N0 496 425 div N0, 0.01 497 print N0 498 print "\n" 426 say N0 499 427 end 500 428 CODE 501 429 -0.03078075 … … 512 440 set N2, 4000.246 513 441 set N0, -123.123 514 442 add N1, N0, N2 515 print N1 516 print "\n" 443 say N1 517 444 add N0, N0, N2 518 print N0 519 print "\n" 445 say N0 520 446 end 521 447 CODE 522 448 3877.123 … … 527 453 set N2, 4000.246 528 454 set N0, -123.123 529 455 sub N1, N0, N2 530 print N1 531 print "\n" 456 say N1 532 457 sub N0, N0, N2 533 print N0 534 print "\n" 458 say N0 535 459 end 536 460 CODE 537 461 -4123.369 … … 542 466 set N2, 4000.246 543 467 set N0, -123.123 544 468 mul N1, N0, N2 545 print N1 546 print "\n" 469 say N1 547 470 mul N0, N0, N2 548 print N0 549 print "\n" 471 say N0 550 472 end 551 473 CODE 552 474 -492522.288258 … … 557 479 set N2, 4000.246 558 480 set N0, -123.123 559 481 div N1, N0, N2 560 print N1 561 print "\n" 482 say N1 562 483 div N0, N0, N2 563 print N0 564 print "\n" 484 say N0 565 485 end 566 486 CODE 567 487 -0.0307788571002883 … … 574 494 lcm I2, I1, I0 575 495 eq I2, 10, OK1 576 496 print "not " 577 OK1: print "ok 1\n"497 OK1: say "ok 1" 578 498 579 499 set I1, 17 580 500 lcm I2, I1, I0 -
config/auto/neg_0.pm
old new 1 # Copyright (C) 200 6-2007, The Perl Foundation.2 # $Id: neg_0.pm 30367 2008-08-20 02:21:59Z jkeenan $1 # Copyright (C) 2009, The Perl Foundation. 2 # $Id: neg_0.pm 30367 2008-08-20 02:21:59Z rurban $ 3 3 4 4 =head1 NAME 5 5 … … 7 7 8 8 =head1 DESCRIPTION 9 9 10 Determines whether print -0.0 can print -0 or just 0.10 Determines whether print -0.0 can print "-0" or just prints "0" 11 11 12 12 This needs workarounds on older win32 (msvcrt.dll) and openbsd. 13 13 … … 33 33 34 34 sub runstep { 35 35 my ( $self, $conf ) = @_; 36 37 my $d_negative_zero = _probe_for_negative_zero($conf); 38 39 $self->_evaluate_negative_zero($conf, $d_negative_zero); 36 my ( $verbose ) = $conf->options->get('verbose'); 37 $conf->cc_gen('config/auto/neg_0/test_c.in'); 38 eval { $conf->cc_build( q{} ); }; 39 my $has_neg_0 = 0; 40 if ( !$@ ) { 41 my $test = $conf->cc_run(); 42 $has_neg_0 = $self->_evaluate_cc_run($conf, $test, $has_neg_0, $verbose); 43 } 44 $conf->cc_clean(); 45 $conf->data->set( has_negative_zero => $has_neg_0 ); 40 46 41 47 return 1; 42 48 } 43 49 44 sub _probe_for_negative_zero { 45 my $conf = shift; 46 return $conf->data->get('has_negative_zero') 47 || 48 $conf->data->get_p5('d_negative_zero'); 49 } 50 51 sub _evaluate_negative_zero { 52 my ($self, $conf, $d_negative_zero) = @_; 53 my $has_negative_zero = $d_negative_zero ? 1 : 0; 54 $self->set_result( $has_negative_zero ? 'yes' : 'no' ); 55 $conf->data->set( has_negative_zero => $has_negative_zero ); 50 sub _evaluate_cc_run { 51 my $self = shift; 52 my ($conf, $test, $has_neg_0, $verbose) = @_; 53 if ( $test =~ m/^-0/ ) { 54 $has_neg_0 = 1; 55 $self->set_result( $has_neg_0 ? 'yes' : 'no' ); 56 $conf->data->set( has_negative_zero => $has_neg_0 ); 57 print " (yes) " if $verbose; 58 } 59 return $has_neg_0; 56 60 } 57 61 58 62 1; -
(a) /dev/null vs. (b) parrot-svn/t/steps/auto_neg_0-01.t
a b 1 #! perl 2 # Copyright (C) 2009, The Perl Foundation. 3 # $Id: auto_socklen_t-01.t 30640 2008-08-29 23:09:28Z jkeenan $ 4 # auto_neg_0-01.t 5 6 use strict; 7 use warnings; 8 use Test::More tests => 16; 9 use Carp; 10 use lib qw( lib t/configure/testlib ); 11 use_ok('config::auto::socklen_t'); 12 use Parrot::Configure; 13 use Parrot::Configure::Options qw( process_options ); 14 use Parrot::Configure::Test qw( 15 test_step_thru_runstep 16 rerun_defaults_for_testing 17 test_step_constructor_and_description 18 ); 19 use IO::CaptureOutput qw| capture |; 20 21 ########### regular ########### 22 23 my ($args, $step_list_ref) = process_options( 24 { 25 argv => [ ], 26 mode => q{configure}, 27 } 28 ); 29 30 my $conf = Parrot::Configure->new; 31 32 my $pkg = q{auto::neg_0}; 33 34 $conf->add_steps($pkg); 35 36 my $serialized = $conf->pcfreeze(); 37 38 $conf->options->set( %{$args} ); 39 my $step = test_step_constructor_and_description($conf); 40 my $ret = $step->runstep($conf); 41 ok( $ret, "runstep() returned true value" ); 42 ok(defined($step->result()), "A result has been defiined"); 43 44 $conf->replenish($serialized); 45 46 ##### _evaluate_neg_0_t() ##### 47 48 ($args, $step_list_ref) = process_options( 49 { 50 argv => [ ], 51 mode => q{configure}, 52 } 53 ); 54 $conf->options->set( %{$args} ); 55 $step = test_step_constructor_and_description($conf); 56 57 my $d_neg_zero; 58 59 $d_neg_zero = q{-0}; 60 ok($step->_evaluate_cc_run($conf, $d_neg_zero), 61 "_evaluate_cc_run() completed satisfactorily"); 62 is($step->result(), q{yes}, "Got expected result"); 63 is($conf->data->get('has_negative_zero'), 1, 64 "has_negative_zero set as expected"); 65 66 $d_neg_zero = q{0}; 67 ok($step->_evaluate_cc_run($conf, $d_neg_zero), 68 "_evaluate_cc_run() completed satisfactorily"); 69 is($step->result(), q{no}, "Got expected result"); 70 is($conf->data->get('has_negative_zero'), 0, 71 "has_negative_zero set as expected"); 72 73 pass("Completed all tests in $0"); 74 75 ################### DOCUMENTATION ################### 76 77 =head1 NAME 78 79 auto_neg_0-01.t - test auto::neg_0 80 81 =head1 SYNOPSIS 82 83 % prove t/steps/auto_neg_0-01.t 84 85 =head1 DESCRIPTION 86 87 The files in this directory test functionality used by F<Configure.pl>. 88 89 The tests in this file test auto::neg_0. 90 91 =head1 AUTHOR 92 93 Reini Urban 94 95 =head1 SEE ALSO 96 97 config::auto::neg_0, F<Configure.pl>. 98 99 =cut 100 101 # Local Variables: 102 # mode: cperl 103 # cperl-indent-level: 4 104 # fill-column: 100 105 # End: 106 # vim: expandtab shiftwidth=4: -
parrot-svn
old new 273 273 config/auto/memalign/test_c.in [] 274 274 config/auto/msvc.pm [] 275 275 config/auto/msvc/test_c.in [] 276 config/auto/neg_0.pm [] 277 config/auto/neg_0/test_c.in [] 276 278 config/auto/opengl.pm [] 277 279 config/auto/opengl/opengl_c.in [] 278 280 config/auto/ops.pm [] … … 3247 3249 t/steps/auto_macports-02.t [] 3248 3250 t/steps/auto_memalign-01.t [] 3249 3251 t/steps/auto_msvc-01.t [] 3252 t/steps/auto_neg_0-01.t [] 3250 3253 t/steps/auto_opengl-01.t [] 3251 3254 t/steps/auto_ops-01.t [] 3252 3255 t/steps/auto_pcre-01.t [] -
(a) /dev/null vs. (b) parrot-svn/config/auto/neg_0/test_c.in
a b 1 #include <stdio.h> 2 3 int 4 main(int argc, char* argv[]) 5 { 6 printf("%.0f", -0.0); 7 return 0; 8 } -
config/gen/config_h/feature_h.in
old new 154 154 155 155 print OUT <<'END_PRINT'; 156 156 157 /* from config/auto/neg_0 */ 158 END_PRINT 159 if (@has_negative_zero@) { 160 print OUT <<'END_PRINT'; 161 #define PARROT_HAS_NEGATIVE_ZERO 1 162 END_PRINT 163 } 164 165 print OUT <<'END_PRINT'; 157 166 158 167 #endif /* PARROT_FEATURE_H_GUARD */ 159 168 END_PRINT -
src/ops/io.ops
old new 152 152 } 153 153 154 154 inline op print(in NUM) :base_io { 155 #ifdef PARROT_HAS_NEGATIVE_ZERO 155 156 Parrot_io_printf(interp, FLOATVAL_FMT, $1); 157 #else 158 /* Workaround for older msvcrt and openbsd. TT #313 */ 159 if ($1 == -0.0) { 160 Parrot_io_printf(interp, "-0"); 161 } 162 else { 163 Parrot_io_printf(interp, FLOATVAL_FMT, $1); 164 } 165 #endif 156 166 } 157 167 158 168 op print(in STR) :base_io { … … 185 195 } 186 196 187 197 inline op say(in NUM) :base_io { 198 #ifdef PARROT_HAS_NEGATIVE_ZERO 188 199 Parrot_io_printf(interp, FLOATVAL_FMT "\n", $1); 200 #else 201 /* Workaround for older msvcrt and openbsd. TT #313 */ 202 if ($1 == -0.0) { 203 Parrot_io_printf(interp, "-0\n"); 204 } 205 else { 206 Parrot_io_printf(interp, FLOATVAL_FMT "\n", $1); 207 } 208 #endif 189 209 } 190 210 191 211 op say(in STR) :base_io {