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]

Re: [PATCH] Optimize pow(x,0.0) = pow(1.0,y) = 1.0

On Thu, 20 Feb 2003, Andrew Pinski wrote:
> Did you know that pow(0.0, 0.0) != 1.0?

I'm using as reference "IA-64 and Elementary Functions: Speed and
Precision", by Peter Markstein, HP Professional Books, 2000.

Section 12.6, entitled "Computing the Power Function" begins with
the paragraph.

	To demonstrate the care needed for the power function, and
	the many special cases required by C99 in an IEEE 754
	implementation, we present a double precision power routine.
	C99 requires the following results from the power function:

	pow(x,+-0) returns 1 for any x, even a NaN.
	pow(+-0,y) raises the divide-by-zero exception and returns
		+-Inf for y < 0 and an odd integer, or +Inf for
		other y < 0.
	pow(+-0,y) returns +-0 for y > 0 and an odd integer, or
		+0 for other y > 0.

I apologise that my reference is non-authorative.  Can someone
confirm the wording in the actual ISO C99 specification?

> Also does you patch work when fast-math is off, it looks like it does
> so you should have a test case for all, including -O0 instead?

Whilst it is true that this optimization is currently also applied at
-O0 and other levels of optimization, the test was intended to
excercise the code in question, rather than specify whether it took
place at -Os, etc...  By running gcc.dg/builtins-5.c at -ffast-math,
I was hoping it could be shared by the other "pow" transformations,
some of which only occur with flag_unsafe_math_optimizations.

If you feel strongly, I can move it to gcc.c-torture/execute and
keep the remaining tests separate.


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