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  
    5050    auto::memalign 
    5151    auto::signal 
    5252    auto::socklen_t 
     53    auto::neg_0 
    5354    auto::env 
    5455    auto::gmp 
    5556    auto::readline 
  • t/op/arithmetics.t

    old new  
    3333pasm_output_is( <<'CODE', <<OUTPUT, "take the negative of a native integer" ); 
    3434        set I0, 0 
    3535        neg I0 
    36         print I0 
    37         print "\n" 
     36        say I0 
    3837        set I0, 1234567890 
    3938        neg I0 
    40         print I0 
    41         print "\n" 
     39        say I0 
    4240        set I0, -1234567890 
    4341        neg I0 
    44         print I0 
    45         print "\n" 
     42        say I0 
    4643        set I0, 0 
    4744        set I1, 0 
    4845        neg I1, I0 
    49         print I1 
    50         print "\n" 
     46        say I1 
    5147        set I0, 1234567890 
    5248        neg I1, I0 
    53         print I1 
    54         print "\n" 
     49        say I1 
    5550        set I0, -1234567890 
    5651        neg I1, I0 
    57         print I1 
    58         print "\n" 
     52        say I1 
    5953        end 
    6054CODE 
    61550 
     
    6963pasm_output_is( <<'CODE', <<OUTPUT, "take the absolute of a native integer" ); 
    7064        set I0, 0 
    7165        abs I0 
    72         print I0 
    73         print "\n" 
     66        say I0 
    7467        set I0, 1234567890 
    7568        abs I0 
    76         print I0 
    77         print "\n" 
     69        say I0 
    7870        set I0, -1234567890 
    7971        abs I0 
    80         print I0 
    81         print "\n" 
     72        say I0 
    8273        set I0, 0 
    8374        set I1, 0 
    8475        abs I1, I0 
    85         print I1 
    86         print "\n" 
     76        say I1 
    8777        set I0, 1234567890 
    8878        abs I1, I0 
    89         print I1 
    90         print "\n" 
     79        say I1 
    9180        set I0, -1234567890 
    9281        abs I1, I0 
    93         print I1 
    94         print "\n" 
     82        say I1 
    9583        end 
    9684CODE 
    97850 
     
    10997        set I0, 4000 
    11098        set I1, -123 
    11199        add I2, I0, I1 
    112         print I2 
    113         print "\n" 
     100        say I2 
    114101        add I0, I0, I1 
    115         print I0 
    116         print "\n" 
     102        say I0 
    117103        end 
    118104CODE 
    1191053877 
     
    124110        set I0, 4000 
    125111        set I1, -123 
    126112        sub I2, I0, I1 
    127         print I2 
    128         print "\n" 
     113        say I2 
    129114        sub I0, I0, I1 
    130         print I0 
    131         print "\n" 
     115        say I0 
    132116        end 
    133117CODE 
    1341184123 
     
    139123        set I0, 4000 
    140124        set I1, -123 
    141125        mul I2, I0, I1 
    142         print I2 
    143         print "\n" 
     126        say I2 
    144127        mul I0, I0, I1 
    145         print I0 
    146         print "\n" 
     128        say I0 
    147129        end 
    148130CODE 
    149131-492000 
     
    154136        set I0, 4000 
    155137        set I1, -123 
    156138        div I2, I0, I1 
    157         print I2 
    158         print "\n" 
     139        say I2 
    159140        div I0, I0, I1 
    160         print I0 
    161         print "\n" 
     141        say I0 
    162142        end 
    163143CODE 
    164144-32 
     
    177157pasm_output_is( <<'CODE', <<OUTPUT, 'negate -0.0', @todo ); 
    178158        set N0, 0 
    179159        neg N0 
    180         print N0 
    181         print "\n" 
     160        say N0 
    182161        set N0, -0.0 
    183162        neg N0 
    184         print N0 
    185         print "\n" 
     163        say N0 
    186164        set N0, -0.0 
    187165        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 
    190172CODE 
    191173-0 
    1921740 
    193 -0 
    1941750 
     176-0 
    195177OUTPUT 
    196178 
    197179} 
     
    204186pasm_output_is( <<'CODE', <<OUTPUT, 'negate a native number' ); 
    205187        set N0, 123.4567890 
    206188        neg N0 
    207         print N0 
    208         print "\n" 
     189        say N0 
    209190        set N0, -123.4567890 
    210191        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 
    218193        set N0, 123.4567890 
    219194        neg N1, N0 
    220         print N1 
    221         print "\n" 
     195        say N1 
    222196        set N0, -123.4567890 
    223197        neg N1, N0 
    224         print N1 
    225         print "\n" 
     198        say N1 
    226199        end 
    227200CODE 
    228201-123.456789 
    229202123.456789 
    230 0 
    231203-123.456789 
    232204123.456789 
    233205OUTPUT 
     
    235207pasm_output_is( <<'CODE', <<OUTPUT, "take the absolute of a native number" ); 
    236208        set N0, 0 
    237209        abs N0 
    238         print N0 
    239         print "\n" 
     210        say N0 
    240211        set N0, -0.0 
    241212        abs N0 
    242         print N0 
    243         print "\n" 
     213        say N0 
    244214        set N0, 123.45678901 
    245215        abs N0 
    246         print N0 
    247         print "\n" 
     216        say N0 
    248217        set N0, -123.45678901 
    249218        abs N0 
    250         print N0 
    251         print "\n" 
     219        say N0 
    252220        set N0, 0 
    253221        set N1, 1 
    254222        abs N1, N0 
    255         print N1 
    256         print "\n" 
     223        say N1 
    257224        set N0, 0.0 
    258225        set N1, 1 
    259226        abs N1, N0 
    260         print N1 
    261         print "\n" 
     227        say N1 
    262228        set N0, 123.45678901 
    263229        set N1, 1 
    264230        abs N1, N0 
    265         print N1 
    266         print "\n" 
     231        say N1 
    267232        set N0, -123.45678901 
    268233        set N1, 1 
    269234        abs N1, N0 
    270         print N1 
    271         print "\n" 
     235        say N1 
    272236        end 
    273237CODE 
    2742380 
     
    284248pasm_output_is( <<'CODE', <<OUTPUT, "ceil of a native number" ); 
    285249       set N0, 0 
    286250       ceil N0 
    287        print N0 
    288        print "\n" 
     251       say N0 
    289252       set N0, 123.45678901 
    290253       ceil N0 
    291        print N0 
    292        print "\n" 
     254       say N0 
    293255       set N0, -123.45678901 
    294256       ceil N0 
    295        print N0 
    296        print "\n" 
     257       say N0 
    297258       set N0, 0 
    298259       set N1, 1 
    299260       ceil N1, N0 
    300        print N1 
    301        print "\n" 
     261       say N1 
    302262       set N0, 0.0 
    303263       set N1, 1 
    304264       ceil N1, N0 
    305        print N1 
    306        print "\n" 
     265       say N1 
    307266       set N0, 123.45678901 
    308267       set N1, 1 
    309268       ceil N1, N0 
    310        print N1 
    311        print "\n" 
     269       say N1 
    312270       set N0, -123.45678901 
    313271       set N1, 1 
    314272       ceil N1, N0 
    315        print N1 
    316        print "\n" 
     273       say N1 
    317274       set N0, 0 
    318275       set I1, 1 
    319276       ceil I1, N0 
    320        print I1 
    321        print "\n" 
     277       say I1 
    322278       set N0, 0.0 
    323279       set I1, 1 
    324280       ceil I1, N0 
    325        print I1 
    326        print "\n" 
     281       say I1 
    327282       set N0, 123.45678901 
    328283       set I1, 1 
    329284       ceil I1, N0 
    330        print I1 
    331        print "\n" 
     285       say I1 
    332286       set N0, -123.45678901 
    333287       set I1, 1 
    334288       ceil I1, N0 
    335        print I1 
    336        print "\n" 
     289       say I1 
    337290       end 
    338291CODE 
    3392920 
     
    352305pasm_output_is( <<'CODE', <<OUTPUT, "floor of a native number" ); 
    353306       set N0, 0 
    354307       floor N0 
    355        print N0 
    356        print "\n" 
     308       say N0 
    357309       set N0, 123.45678901 
    358310       floor N0 
    359        print N0 
    360        print "\n" 
     311       say N0 
    361312       set N0, -123.45678901 
    362313       floor N0 
    363        print N0 
    364        print "\n" 
     314       say N0 
    365315       set N0, 0 
    366316       set N1, 1 
    367317       floor N1, N0 
    368        print N1 
    369        print "\n" 
     318       say N1 
    370319       set N0, 0.0 
    371320       set N1, 1 
    372321       floor N1, N0 
    373        print N1 
    374        print "\n" 
     322       say N1 
    375323       set N0, 123.45678901 
    376324       set N1, 1 
    377325       floor N1, N0 
    378        print N1 
    379        print "\n" 
     326       say N1 
    380327       set N0, -123.45678901 
    381328       set N1, 1 
    382329       floor N1, N0 
    383        print N1 
    384        print "\n" 
     330       say N1 
    385331       set N0, 0 
    386332       set I1, 1 
    387333       floor I1, N0 
    388        print I1 
    389        print "\n" 
     334       say I1 
    390335       set N0, 0.0 
    391336       set I1, 1 
    392337       floor I1, N0 
    393        print I1 
    394        print "\n" 
     338       say I1 
    395339       set N0, 123.45678901 
    396340       set I1, 1 
    397341       floor I1, N0 
    398        print I1 
    399        print "\n" 
     342       say I1 
    400343       set N0, -123.45678901 
    401344       set I1, 1 
    402345       floor I1, N0 
    403        print I1 
    404        print "\n" 
     346       say I1 
    405347       end 
    406348CODE 
    4073490 
     
    424366        set I0, 4000 
    425367        set N0, -123.123 
    426368        add N1, N0, I0 
    427         print N1 
    428         print "\n" 
     369        say N1 
    429370        add N0, N0, I0 
    430         print N0 
    431         print "\n" 
     371        say N0 
    432372        add N0, I0 
    433         print N0 
    434         print "\n" 
     373        say N0 
    435374        end 
    436375CODE 
    4373763876.877 
     
    443382        set I0, 4000 
    444383        set N0, -123.123 
    445384        sub N1, N0, I0 
    446         print N1 
    447         print "\n" 
     385        say N1 
    448386        sub N0, N0, I0 
    449         print N0 
    450         print "\n" 
     387        say N0 
    451388        sub N0, I0 
    452         print N0 
    453         print "\n" 
     389        say N0 
    454390        end 
    455391CODE 
    456392-4123.123 
     
    462398        set I0, 4000 
    463399        set N0, -123.123 
    464400        mul N1, N0, I0 
    465         print N1 
    466         print "\n" 
     401        say N1 
    467402        mul N0, N0, I0 
    468         print N0 
    469         print "\n" 
     403        say N0 
    470404        mul N0, -2 
    471         print N0 
    472         print "\n" 
     405        say N0 
    473406        end 
    474407CODE 
    475408-492492 
     
    481414        set I0, 4000 
    482415        set N0, -123.123 
    483416        div N1, N0, I0 
    484         print N1 
    485         print "\n" 
     417        say N1 
    486418        div N0, N0, I0 
    487         print N0 
    488         print "\n" 
     419        say N0 
    489420        div N0, 1 
    490         print N0 
    491         print "\n" 
     421        say N0 
    492422        set N0, 100.000 
    493423        div N0, 100 
    494         print N0 
    495         print "\n" 
     424        say N0 
    496425        div N0, 0.01 
    497         print N0 
    498         print "\n" 
     426        say N0 
    499427        end 
    500428CODE 
    501429-0.03078075 
     
    512440        set N2, 4000.246 
    513441        set N0, -123.123 
    514442        add N1, N0, N2 
    515         print N1 
    516         print "\n" 
     443        say N1 
    517444        add N0, N0, N2 
    518         print N0 
    519         print "\n" 
     445        say N0 
    520446        end 
    521447CODE 
    5224483877.123 
     
    527453        set N2, 4000.246 
    528454        set N0, -123.123 
    529455        sub N1, N0, N2 
    530         print N1 
    531         print "\n" 
     456        say N1 
    532457        sub N0, N0, N2 
    533         print N0 
    534         print "\n" 
     458        say N0 
    535459        end 
    536460CODE 
    537461-4123.369 
     
    542466        set N2, 4000.246 
    543467        set N0, -123.123 
    544468        mul N1, N0, N2 
    545         print N1 
    546         print "\n" 
     469        say N1 
    547470        mul N0, N0, N2 
    548         print N0 
    549         print "\n" 
     471        say N0 
    550472        end 
    551473CODE 
    552474-492522.288258 
     
    557479        set N2, 4000.246 
    558480        set N0, -123.123 
    559481        div N1, N0, N2 
    560         print N1 
    561         print "\n" 
     482        say N1 
    562483        div N0, N0, N2 
    563         print N0 
    564         print "\n" 
     484        say N0 
    565485        end 
    566486CODE 
    567487-0.0307788571002883 
     
    574494        lcm I2, I1, I0 
    575495        eq I2, 10, OK1 
    576496        print "not " 
    577 OK1:    print "ok 1\n" 
     497OK1:    say "ok 1" 
    578498 
    579499        set I1, 17 
    580500        lcm I2, I1, I0 
  • config/auto/neg_0.pm

    old new  
    1 # Copyright (C) 2006-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 $ 
    33 
    44=head1 NAME 
    55 
     
    77 
    88=head1 DESCRIPTION 
    99 
    10 Determines whether print -0.0 can print -0 or just 0. 
     10Determines whether print -0.0 can print "-0" or just prints "0" 
    1111 
    1212This needs workarounds on older win32 (msvcrt.dll) and openbsd. 
    1313 
     
    3333 
    3434sub runstep { 
    3535    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 ); 
    4046 
    4147    return 1; 
    4248} 
    4349 
    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 ); 
     50sub _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; 
    5660} 
    5761 
    58621; 
  • (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 
     6use strict; 
     7use warnings; 
     8use Test::More tests => 16; 
     9use Carp; 
     10use lib qw( lib t/configure/testlib ); 
     11use_ok('config::auto::socklen_t'); 
     12use Parrot::Configure; 
     13use Parrot::Configure::Options qw( process_options ); 
     14use Parrot::Configure::Test qw( 
     15    test_step_thru_runstep 
     16    rerun_defaults_for_testing 
     17    test_step_constructor_and_description 
     18); 
     19use IO::CaptureOutput qw| capture |; 
     20 
     21########### regular ########### 
     22 
     23my ($args, $step_list_ref) = process_options( 
     24    { 
     25        argv => [ ], 
     26        mode => q{configure}, 
     27    } 
     28); 
     29 
     30my $conf = Parrot::Configure->new; 
     31 
     32my $pkg = q{auto::neg_0}; 
     33 
     34$conf->add_steps($pkg); 
     35 
     36my $serialized = $conf->pcfreeze(); 
     37 
     38$conf->options->set( %{$args} ); 
     39my $step = test_step_constructor_and_description($conf); 
     40my $ret = $step->runstep($conf); 
     41ok( $ret, "runstep() returned true value" ); 
     42ok(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 
     57my $d_neg_zero; 
     58 
     59$d_neg_zero = q{-0}; 
     60ok($step->_evaluate_cc_run($conf, $d_neg_zero), 
     61    "_evaluate_cc_run() completed satisfactorily"); 
     62is($step->result(), q{yes}, "Got expected result"); 
     63is($conf->data->get('has_negative_zero'), 1, 
     64    "has_negative_zero set as expected"); 
     65 
     66$d_neg_zero = q{0}; 
     67ok($step->_evaluate_cc_run($conf, $d_neg_zero), 
     68    "_evaluate_cc_run() completed satisfactorily"); 
     69is($step->result(), q{no}, "Got expected result"); 
     70is($conf->data->get('has_negative_zero'), 0, 
     71    "has_negative_zero set as expected"); 
     72 
     73pass("Completed all tests in $0"); 
     74 
     75################### DOCUMENTATION ################### 
     76 
     77=head1 NAME 
     78 
     79auto_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 
     87The files in this directory test functionality used by F<Configure.pl>. 
     88 
     89The tests in this file test auto::neg_0. 
     90 
     91=head1 AUTHOR 
     92 
     93Reini Urban 
     94 
     95=head1 SEE ALSO 
     96 
     97config::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  
    273273config/auto/memalign/test_c.in                              [] 
    274274config/auto/msvc.pm                                         [] 
    275275config/auto/msvc/test_c.in                                  [] 
     276config/auto/neg_0.pm                                        [] 
     277config/auto/neg_0/test_c.in                                 [] 
    276278config/auto/opengl.pm                                       [] 
    277279config/auto/opengl/opengl_c.in                              [] 
    278280config/auto/ops.pm                                          [] 
     
    32473249t/steps/auto_macports-02.t                                  [] 
    32483250t/steps/auto_memalign-01.t                                  [] 
    32493251t/steps/auto_msvc-01.t                                      [] 
     3252t/steps/auto_neg_0-01.t                                     [] 
    32503253t/steps/auto_opengl-01.t                                    [] 
    32513254t/steps/auto_ops-01.t                                       [] 
    32523255t/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 
     3int 
     4main(int argc, char* argv[]) 
     5{ 
     6    printf("%.0f", -0.0); 
     7    return 0; 
     8} 
  • config/gen/config_h/feature_h.in

    old new  
    154154 
    155155print OUT <<'END_PRINT'; 
    156156 
     157/* from config/auto/neg_0 */ 
     158END_PRINT 
     159if (@has_negative_zero@) { 
     160    print OUT <<'END_PRINT'; 
     161#define PARROT_HAS_NEGATIVE_ZERO 1 
     162END_PRINT 
     163} 
     164 
     165print OUT <<'END_PRINT'; 
    157166 
    158167#endif /* PARROT_FEATURE_H_GUARD */ 
    159168END_PRINT 
  • src/ops/io.ops

    old new  
    152152} 
    153153 
    154154inline op print(in NUM) :base_io { 
     155#ifdef PARROT_HAS_NEGATIVE_ZERO 
    155156  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 
    156166} 
    157167 
    158168op print(in STR) :base_io { 
     
    185195} 
    186196 
    187197inline op say(in NUM) :base_io { 
     198#ifdef PARROT_HAS_NEGATIVE_ZERO 
    188199  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 
    189209} 
    190210 
    191211op say(in STR) :base_io {