Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Seeing if two numbers have the same sign

by poolpi (Hermit)
on Jan 11, 2008 at 09:55 UTC ( [id://661841]=note: print w/replies, xml ) Need Help??


in reply to Re: Seeing if two numbers have the same sign
in thread Seeing if two numbers have the same sign

Works under XP with Cygwin 1.5.24-2 but not under Linux 2.6.18-4-686 !

This one works under Linux 2.6.18-4-686 with Perl v5.8.8 :
#!/usr/bin/perl use strict; use warnings; sub same_sign { my $i=0; printf( "%2d %2d => ", $_[0], $_[1] ); s/-/$i=$i+1;/e for @_; $i!~/1/; } my $val = [ [ 1, 2 ], [ -1, 2 ], [ 1, -2 ], [ -1, -2 ] ]; for ( 0 .. $#{$val} ) { my ( $x, $y ) = ( $val->[$_][0], $val->[$_][1] ); print same_sign( $x, $y ) ? '' : 'not ', "same sign\n"; }
Output:
1 2 => same sign -1 2 => not same sign 1 -2 => not same sign -1 -2 => same sign


PooLpi

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://661841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-25 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found