Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday October 19, 2004
01:31 PM

Is It Negative?

[ #21417 ]

Stolen from The Daily WTF.

//return whether a double is negative
bool IsNegative(double n)
{
    string nStr = n.ToString();
    if (nstr.IndexOf('-', 0, 1)) return true;
    return false;
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Crazy as it may seem, it seems about the simplest way to partition negative zero with all the other negative numbers. But I doubt that the original author had that in mind :-) [or should that be :-(]

  • ...but I did write something to find garbage consecutive records in a database (first record was positive, second was duplicate but negative), that went something like:

    my @comp_fields = qw(field1 field2 etc.);
    ...
    if (is_crap(\%old_rec, \%this_rec, @comp_fields) {
      ...delete the records
    }
    ...
    sub is_crap {
      my $rec1 = shift;
      my $rec2 = shift;
      for my $field (@_) {
        return unless "-$rec1->{$field}" eq $rec2->{$field};
      }
      1;
    }