Re: Meaning of Double.Epsilon
From: Niki Estner (niki.estner_at_cube.net)
Date: 09/10/04
- Next message: Niki Estner: "Re: What's wrong with this regular expression?"
- Previous message: Tobe: "Running Successive Console Apps from C#"
- In reply to: cody: "Re: Meaning of Double.Epsilon"
- Next in thread: cody: "Re: Meaning of Double.Epsilon"
- Reply: cody: "Re: Meaning of Double.Epsilon"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 10 Sep 2004 21:37:12 +0200
"cody" <please_dont.spam.deutronium@gmx.de> wrote in
news:e0VDug2lEHA.1652@TK2MSFTNGP09.phx.gbl...
>> That's the point I've already tried to say: I *do* use tests like "if (a
>> == -1) a = DoLazyCalculation();" and the like; I'd also guess the
>> equality
>> operator is implicitly used when you use doubles as keys in a hashtable,
> or
>> sort an array of doubles (at least with generics, things like this should
>> trigger your warning, too). I don't think it would be a good idea to have
> a
>> warning *every* time the == operator is used on fp values;
>
> using -1 is imho a bad idea. what if you actually need -1 in your app?
> Negative numbers are very common in floating point (in contrast to
> integers). What if you inadvertantly use the float variable with its -1
> value?
> NaN is just for that purpose: If a value is NaN it stays NaN even if used
> in
> calculations or converted from double to float and vice versa and this
> way,
> you know that something gone wrong if you see NaN in the output.
> The following code displays 4 times NaN:
I think this is going slightly off-topic now, but of course "special values"
like these have to be values that cannot be result of a calculation.
Depending on the meaning of the value this could be a negative value (e.g
distances), NaN, a value above 100 (percentages), or whatever. Although NaN
is a good "special value", too, it does have disadvantages, sometimes: AFAIK
Double.Parse can't parse it, converting it to an int will throw an
exception, you only have one single special value, and sometimes NaN can be
result of a calculation...
Niki
- Next message: Niki Estner: "Re: What's wrong with this regular expression?"
- Previous message: Tobe: "Running Successive Console Apps from C#"
- In reply to: cody: "Re: Meaning of Double.Epsilon"
- Next in thread: cody: "Re: Meaning of Double.Epsilon"
- Reply: cody: "Re: Meaning of Double.Epsilon"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|