Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by Corion (Patriarch)
on Jan 11, 2008 at 17:02 UTC ( [id://661915]=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

I suggest you test your code before posting:

use strict; sub same_sign { my ($x,$y) = @_; if ( undef($x) or undef($y)) { return 0; # "undef" is never same-sign } if ( ( ($x >= 0) and ($y >= 0) ) or ( ($x < 0) and ($y < 0) ) ) { return 1; } else { return 0; } } $\ = "\n"; print same_sign(1,1); print same_sign(0,0); print same_sign(undef,undef); print same_sign(-1,-1); print same_sign(-2,-2); print same_sign(2,-2); __END__ 1 1 1 1 1 1

Your subroutine seems to suggest that all values passed in always have the same value sign...

Update: Correction thanks to lodin

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 05:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found