Is It Negative?

Ovid on 2004-10-19T18:31:59

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;
}


-0

nicholas on 2004-10-19T20:18:12

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 :-(]

I swear I didn't do it...

runrig on 2004-10-20T05:33:52

...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;
}