[HACKERS] random_fract and aix compiler bug

Started by Zeugswetter Andreas SB SDalmost 23 years ago7 messagespatches
Jump to latest
#1Zeugswetter Andreas SB SD
ZeugswetterA@spardat.at

Hi Peter,

While fighting with a compiler bug here, I came across the following code,
that loops here (on AIX 4.3.2) due to a compiler bug,
presumably with the z < MAX_RANDOM_VALUE (it even warns at compile time):

static double
random_fract(void)
{
long z;

/* random() can produce endpoint values, try again if so */
do
{
z = random();
} while (!(z > 0 && z < MAX_RANDOM_VALUE));
return (double) z / (double) MAX_RANDOM_VALUE;
}

Since you where the last to commit on analyze.c I send you this mail,
since my mails currently don't pass some filter on postgresql.org

I have attached a patch as a workaround for this silly compiler bug.
Please consider to apply, Thanks

Andreas

Attachments:

analyze.patchapplication/octet-stream; name=analyze.patchDownload+2-2
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Zeugswetter Andreas SB SD (#1)
Re: [HACKERS] random_fract and aix compiler bug

"Zeugswetter Andreas SB SD" <ZeugswetterA@spardat.at> writes:

! } while (!(z > 0 && z < MAX_RANDOM_VALUE));

! } while (z == 0 || z == MAX_RANDOM_VALUE);

This seems fairly ugly, since it eliminates the original coding's
positive guarantee that the final result is in 0 < x < 1. Does your
compiler manage not to choke if we add a cast instead?

} while (!(z > 0 && z < (long) MAX_RANDOM_VALUE));

regards, tom lane

#3Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#2)
Re: [HACKERS] random_fract and aix compiler bug

Tom Lane wrote:

"Zeugswetter Andreas SB SD" <ZeugswetterA@spardat.at> writes:

! } while (!(z > 0 && z < MAX_RANDOM_VALUE));

! } while (z == 0 || z == MAX_RANDOM_VALUE);

This seems fairly ugly, since it eliminates the original coding's
positive guarantee that the final result is in 0 < x < 1. Does your
compiler manage not to choke if we add a cast instead?

} while (!(z > 0 && z < (long) MAX_RANDOM_VALUE));

Or put an "L" suffix on the value in pg_config_manual.h, so it gets
picked up everywhere?

cheers

andrew

#4Zeugswetter Andreas SB SD
ZeugswetterA@spardat.at
In reply to: Andrew Dunstan (#3)
Re: [HACKERS] random_fract and aix compiler bug

! } while (!(z > 0 && z < MAX_RANDOM_VALUE));

! } while (z == 0 || z == MAX_RANDOM_VALUE);

This seems fairly ugly, since it eliminates the original coding's
positive guarantee that the final result is in 0 < x < 1. Does your

yes, ugly :-(

compiler manage not to choke if we add a cast instead?

} while (!(z > 0 && z < (long) MAX_RANDOM_VALUE));

this does unfortunately not help, have also tried all sorts of other casts :-(

Would we be happy with the following, which would work ?

} while (z <= 0 || z == MAX_RANDOM_VALUE);

Andreas

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Zeugswetter Andreas SB SD (#4)
Re: [HACKERS] random_fract and aix compiler bug

"Zeugswetter Andreas SB SD" <ZeugswetterA@spardat.at> writes:

Would we be happy with the following, which would work ?
} while (z <= 0 || z == MAX_RANDOM_VALUE);

I suppose this doesn't?
} while (z <= 0 || z >= MAX_RANDOM_VALUE);

regards, tom lane

#6Zeugswetter Andreas SB SD
ZeugswetterA@spardat.at
In reply to: Tom Lane (#5)
Re: [HACKERS] random_fract and aix compiler bug

Would we be happy with the following, which would work ?
} while (z <= 0 || z == MAX_RANDOM_VALUE);

I suppose this doesn't?
} while (z <= 0 || z >= MAX_RANDOM_VALUE);

Ah, yes ! That also works and is a lot nicer. Can you please apply ?

Together with the patch in Bruce's queue, the only minor open issue is now
with the -i switch for postmaster in the getaddrinfo_all area
(on this machine a direct nameservice request answers "host not found"),
and the geometry and horology regression expected files.

Thanks
Andreas

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Zeugswetter Andreas SB SD (#6)
Re: [HACKERS] random_fract and aix compiler bug

"Zeugswetter Andreas SB SD" <ZeugswetterA@spardat.at> writes:

} while (z <= 0 || z >= MAX_RANDOM_VALUE);

Ah, yes ! That also works and is a lot nicer. Can you please apply ?

Done.

regards, tom lane