This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Ada: fix computation of 'Succ in some cases

Tested on x86-linux

There are two issues in this patch. First, in both Pred and Succ, the test
of the sign of the number after testing the fractional part is redundant,
since the fraction always has the same sign as the number. Not only is
this extra test a source of inefficiency, but also for certification
purposes, it results in a test which cannot fail, which makes testing
more complex. The second issue, more serious, is that the constant in
the negative case in Succ should be -0.5, not 0.5. This causes Succ to
compute the wrong result for a negative power of 2. The test program
below illustrates this error, it raises Program_Error if this patch
is not applied, and generates no output if the patch is applied.

with Text_IO; use Text_IO;
procedure k is
   F : Float := -2.0 ** 10;
   if Float'Pred (Float'Succ (F)) /= F then
      raise Program_Error;
   end if;

2004-10-26  Robert Dewar  <>

	* s-fatgen.adb (Pred): Fix redundant test for X > 0.0, since if
	X_Frac = 0.5, then we know that the number X must be positive.
	(Succ): Remove the same redundant test, and also fix the primary test
	to test for X_Frac = -0.5 (used to be 0.5) which is clearly wrong.
	Minor reformatting
	(Decompose): Add fuller comments to spec

Attachment: difs.33
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]