On Thu, 04 Jun 2009 22:10:58 +0400, Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:

Max Samukha wrote:
On Thu, 04 Jun 2009 10:41:31 -0500, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> wrote:

You are mistakenly presupposing that if() takes a bool. In reality if() accepts a bool, an integral, a floating-point type, a pointer, an array, or a class reference.
 or delegate

I was sure I forgot something... and hash too. Anything that can be compared against 0 or null.

Andrei

Is it considered a good practice?

Technically, the following construct is not exactly portable:

float f = ..;
if (f) {
}

because C (nor D) standard doesn't guaranty that float(0) will be implemented as "all bits set to 0" on target platform (although it currently holds true).

I believe it is better to use an epsilon, instead:

if (fabsf(f) < epsilon) {
}

unless you need to compare strictly against 0:

if (f == 0) {
}

Reply via email to