This is the mail archive of the gcc@gcc.gnu.org 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]

Re: rs6000: floating point cast oddities?


And Linus Torvalds writes:
 - 
 - The thing is, I'm not sure I'm right that IEEE math does guarantee the
 - equality between the values of
 - 
 - 	float + float = (float)((double) float + (double) float)
 - 
 - I just have this recollection that it _is_ true.

Replace equality with bit-equals (NaN != NaN), and it is.
See Goldberg's A.7 (Appendix A) of Hennessey and Patterson's 
Computer Architecture, A Quantitative Approach for the 
following statement:

	If x and y have p-bit significands, and x+y is 
	computed exactly and rounded to q places, a second
	rounding to p places will not change the answer if
	q >= 2p+2.  This is true not only for addition,
	but also for multiplication, division, and square
	root.

Proof for multiplication is trivial (product is exact).
Addition in the half-even case isn't too bad (hint: look 
at largest + almost enough to round up), but sqrt and 
division are slightly annoying (hint: prove that half-
way cases cannot occur).  Directed rounding modes are 
easier, and this doesn't rely on gradual underflow (iirc).

IEEE single and double have 24 and 53 bits, respectively,
so that's fine.  As is IEEE single and a double-extended
like Intel's 80- or 82-bit.  IEEE double and Intel's 80-bit 
format are the notable combination that do _not_ keep 
equality.

BTW, C99 allows for all sorts of expression evaluation
methods, even nonsensical ones.  The revised IEEE754
may offer suggestions for language bindings, but I doubt
if it will require much.  If a binding section is added,
either it or its rationale will suggest optimizing the
evaluation of float = float + double 1.0 .  

Indeed, you may even find float = float + double .1 
produces more reliable answers if .1 is converted directly 
to float.  I haven't convinced myself, though.

And if anyone's interested, the IEEE 754 revision meetings
are also available through a conference call.  It may bore
most people to tears, but...  The meeting schedule is at
  http://grouper.ieee.org/groups/754/revision.html#future-meetings
Agendas and the number are sent to the mailing list a few
days before the meetings.

Jason


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