This is sources Bugzilla
Bugzilla Version 2.17.5
Bugzilla Bug 887
  Math library function "logb" and "nextafter" inconsistent Last modified: 2006-09-30 05:54:06
     Query page      Enter new bug
Bug#: 887   Hardware:   Reporter: Uttam Pawar <uttamp@us.ibm.com>
Host: Target: Build:
Product:     Add CC:
Component:   Version:   CC:
Remove selected CCs
Status: ASSIGNED   Priority:  
Resolution:   Severity:  
Assigned To: Ryan S. Arnold <rsa@us.ibm.com>   Target Milestone:  
Flags: Requestee:
  backport ()
  examined ()
  testsuite ()
Summary:
Keywords:

Attachment Description Type Created Actions
logb.patch A propsed patch to fix bug in logb() function on powerpc arch. patch 2005-04-29 20:38 Edit | Diff
nextafter_ppc.patch proposed patch for nextafter() for powerpc patch 2005-07-19 22:16 Edit | Diff
logb.c logb test case demonstrating the described behavior text/plain 2006-09-30 05:02 Edit None
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 887 depends on: Show dependency tree
Show dependency graph
Bug 887 blocks:

Additional Comments:


Leave as ASSIGNED 
Mark bug as waiting for feedback
Mark bug as suspended
Resolve bug, changing resolution to
Resolve bug, mark it as duplicate of bug #
Reassign bug to
Reassign bug to owner of selected component

View Bug Activity   |   Format For Printing


Description:   Last confirmed: 0000-00-00 00:00 Opened: 2005-04-28 17:49
Math library function logb give different result for some input values when 
   rounding mode "towards -ve infinity" is set and not set. Values for which I 
   got miscompare are "0X3FF0000000000000", "0X3FF8000000000000", 
   "0X3FF2000000000000", "0X3FFFFFFFFFFFFFFF", "0X3FF7FFFFFFFFFFFF" and 
   "0X3FF1FFFFFFFFFFFF".

Values obtained when rounding mode "towards -ve infinity" for all above input 
values-
                    "0x8000000000000000"
Values obtained when no rounding mode is set for all above input values-
                     "0x0000000000000000"


Similar problem i have seen with function nextafter - when rounding mode is set
it gives some value and when it is not set gives some value.

------- Additional Comment #1 From Uttam Pawar 2005-04-29 20:38 -------
Created an attachment (id=470)
A propsed patch to fix bug in logb() function on powerpc arch.

------- Additional Comment #2 From Uttam Pawar 2005-06-16 19:12 -------
The patch has been tested for the above platform and did complete clean build.
Did not see any new failures.I'm changing the status from NEW to FIXED. Can it
be verifed and checked in, please?

------- Additional Comment #3 From Uttam Pawar 2005-07-19 22:16 -------
Created an attachment (id=559)
proposed patch for nextafter() for powerpc

A proposed fix for a bug in nextafter() librray function.

------- Additional Comment #4 From Uttam Pawar 2005-10-25 17:05 -------
Ping. Can anybody verify this patch, please? 

------- Additional Comment #5 From Uttam Pawar 2005-11-02 01:29 -------
This patch has not been accepted in the mainline yet. And I would like
maintainer to look at the patch as It has been tested with no new failure and
like to reopen this bug till this patch gets accepted.

------- Additional Comment #6 From Uttam Pawar 2005-11-21 17:57 -------
Ping.

------- Additional Comment #7 From Jakub Jelinek 2005-11-21 18:07 -------
The patch is definitely wrong.
First of all, you haven't proven in any way with standard references that
the current behaviour is incorrect.
If that is a bug (I'm not aware of any part of the standard that would mandate
that), then it would be a generic GCC problem on ppc32 with casts from int
to double with FE_DOWNWARD rounding.  As on ppc32 we can't assume a hw
instruction for that, GCC on ppc32 computes the cast as
((double) (4503601774854144 + i)) - 4503601774854144.0
for int i.  With FE_DOWNWARD rounding and i == 0, this results in -0.0.
Working around this for two randomly picked functions when the same thing
occurs in hundreds of other functions is certainly not the way to go.

------- Additional Comment #8 From Ryan S. Arnold 2006-09-30 05:02 -------
Created an attachment (id=1339)
logb test case demonstrating the described behavior

The included test case demonstrates the described behavior.

------- Additional Comment #9 From Ryan S. Arnold 2006-09-30 05:54 -------
The behavior following fesetround(FE_DOWNWARD) is exhibited on the fsub
operation where f0 and f13 are the same both times fsub is called (before and
after the rounding mode is set):

10000390:       fc 0d 00 28     fsub    f0,f13,f0

The bug doesn't have anything to do with GCC.  The rounding mode is set in the
fpu's FPSCR using the fesetround() function and is applied to the fsub operation.

According to the PowerPC architecture specification for the fsub operation "The
result is rounded to the target precision under control of the Floating-Point
Rounding Control field RN of the FPSCR and placed into register FRT."

Indeed, when the -0.0 result is encountered from fsub following
fesetround(FE_DOWNWARD) the fpscr's rounding mode bits are set for '11' "Round
toward - Infinity":

fpscr          0x4003   16387

And when the 0.0 result is encountered from fsub prior to
fesetround(FE_DOWNWARD) the fpscr's rounding mode bits are set to '00' "Round to
Nearest"

fpscr          0x4000   16384

At worst we're simply encountering the processor defined behavior for fsub.

I reviewed the C99 spec and IEEE754r and could find no mention of logb behavior
regarding rounding mode.  It simply appears to be undefined.

The implementation of logb() makes use of fsub and an identical result is
encountered there.

This same behavior was exhibited on i386.

     Query page      Enter new bug
Actions: New | Query | bug # | Reports | Requests   New Account | Log In