Skip to contentSkip to conversation

New: pow(3): underflow result can be -0.0

Bug 214815 [email protected] 1 participant 5 messages Oct 25, 2021 – Oct 27, 2021 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

https://bugzilla.kernel.org/show_bug.cgi?id=214815

Bug ID: 214815
Summary: pow(3): underflow result can be -0.0
Product: Documentation
Version: unspecified
Hardware: All
OS: Linux
Status: NEW
Severity: low
Priority: P1
Component: man-pages
Assignee: [email protected]
Reporter: [email protected]
Regression: No

The pow(3) man pages as found here:
https://man7.org/linux/man-pages/man3/pow.3.html says...

"If result underflows, and is not representable, a range error occurs, and 0.0 is returned."

That fails to take signs into account. pow(-1e-100,5) produces -0.0, not 0.0

Suggested wording: "... and 0.0 with the appropriate sign is returned."

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#1 lore raw

[Bug 214815] pow(3): underflow result can be -0.0

https://bugzilla.kernel.org/show_bug.cgi?id=214815

--- Comment #1 from Alejandro Colomar (man-pages) ([email protected]) --- [[CC += glibc]]

Hello,

Quoted 19 lines · On 10/26/21 12:33 AM, [email protected] wrote:

https://bugzilla.kernel.org/show_bug.cgi?id=214815

Bug ID: 214815
Summary: pow(3): underflow result can be -0.0
Product: Documentation
Version: unspecified
Hardware: All
OS: Linux
Status: NEW
Severity: low
Priority: P1
Component: man-pages
Assignee: [email protected]
Reporter: [email protected]
Regression: No

The pow(3) man pages as found here:
https://man7.org/linux/man-pages/man3/pow.3.html says...

Quoted 8 lines

"If result underflows, and is not representable, a range error occurs, and 0.0
is returned."

That fails to take signs into account. pow(-1e-100,5) produces -0.0, not 0.0

Suggested wording: "... and 0.0 with the appropriate sign is returned."

I checked the C standard, and it doesn't mention what to do in this case (or I couldn't find it). I also checked POSIX; it says that pow() shall return 0.0 in this case (doesn't specify the sign; should we assume +0.0, or is it a lazy/buggy wording for +/-0.0?). Finally, the glibc manual doesn't mention this special case.

So, is this a bug in glibc?
Or is it a bug in POSIX?
Or is it an undocumented glibc extension?

I checked FreeBSD's manual, and it doesn't mention this special case either.

Thanks,

Alex

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#2 lore raw

[Bug 214815] pow(3): underflow result can be -0.0

In reply to [email protected]

https://bugzilla.kernel.org/show_bug.cgi?id=214815

--- Comment #2 from M Welinder ([email protected]) ---
Hmm... In that case maybe we need glibc's opinion.

fwiw, I couldn't find anything relevant in the C standard either.

A quick test says Solaris also produces -0.0 in this case. And -0.0 is a very reasonable result for underflow from the negative side.

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#3 lore raw

[Bug 214815] pow(3): underflow result can be -0.0

In reply to [email protected]

https://bugzilla.kernel.org/show_bug.cgi?id=214815

--- Comment #3 from [email protected] ---

Quoted 1 line · Alejandro Colomar (man-pages) via Libc-alpha

Finally, the glibc manual doesn't mention this special case.

See math.texi, "Errors in Math Functions".

@item
Each function with a floating-point result behaves as if it computes an infinite-precision result that is within a few ulp (in both real and complex parts, for functions with complex results) of the mathematically correct value of the function (interpreted together with ISO C or POSIX semantics for the function in question) at the exact value passed as the input. Exceptions are raised appropriately for this value and in accordance with IEEE 754 / ISO C / POSIX semantics, and it is then rounded according to the current rounding direction to the result that is returned to the user. @code{errno} may also be set (@pxref{Math Error Reporting}). (The ``inexact'' exception may be raised, or not raised, even if this is inconsistent with the infinite-precision value.)

[...]

@item
If the mathematical result has magnitude well below half the least subnormal magnitude, the returned value is either zero or the least subnormal (in each case, with the correct sign), according to the current rounding direction and with the underflow exception raised.

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.
#4 lore raw

[Bug 214815] pow(3): underflow result can be -0.0

In reply to [email protected]

https://bugzilla.kernel.org/show_bug.cgi?id=214815

--- Comment #4 from Alejandro Colomar (man-pages) ([email protected]) --- Hi Joseph, M.,

Quoted 20 lines · Joseph Myers
Quoted 1 line · Alejandro Colomar (man-pages) via Libc-alpha

Finally, the glibc manual doesn't mention this special case.

See math.texi, "Errors in Math Functions".

@item
Each function with a floating-point result behaves as if it computes an infinite-precision result that is within a few ulp (in both real and complex parts, for functions with complex results) of the mathematically correct value of the function (interpreted together with ISO C or POSIX semantics for the function in question) at the exact value passed as the input. Exceptions are raised appropriately for this value and in accordance with IEEE 754 / ISO C / POSIX semantics, and it is then rounded according to the current rounding direction to the result that is returned to the user. @code{errno} may also be set (@pxref{Math Error Reporting}). (The ``inexact'' exception may be raised, or not raised, even if this is inconsistent with the infinite-precision value.)

Quoted 8 lines

[...]

@item
If the mathematical result has magnitude well below half the least subnormal magnitude, the returned value is either zero or the least subnormal (in each case, with the correct sign), according to the current rounding direction and with the underflow exception raised.

Thanks!

I applied the following 2 patches.

Cheers,

Alex

$ git show -2
commit 2774ebb7e528c3e8b858def471f057044cf33507 (HEAD -> main, alx/main, 
alx/HEAD)
Author: Alejandro Colomar <[email protected]>
Date:   Wed Oct 27 22:01:41 2021 +0200

pow.3: RETURN VALUE: Clarify that -0.0 is a valid underflow result

The standards are a bit unclear (or I couldn't find it), but Joseph confirmed that glibc documents this behavior, and M. Welinder tested that Solaris also behaves in the same way.

man3/pow.3 +1 -1
index ccf6375c0..69ddadc3a 100644
@@ -82,7 +82,7 @@ respectively, with the mathematically correct sign.
  .PP
  If result underflows, and is not representable,
  a range error occurs,
-and 0.0 is returned.
+and 0.0 with the appropriate sign is returned.
  .\" POSIX.1 does not specify the sign of the zero,
  .\" but http://sources.redhat.com/bugzilla/show_bug.cgi?id=2678
  .\" points out that the zero has the wrong sign in some cases.

commit 28df51fc73b5c6986dd8c182d40fa05bba791783

Author: Alejandro Colomar <[email protected]>
Date:   Tue Oct 26 13:36:16 2021 +0200

pow.3: RETURN VALUE: Reorder special cases as in the standard

Use the following order:

- Success
- Over/Underflow
- Special cases specified by the standard (in the same order)
- Other special cases not specified by the standard.

This way it's easier to compare this document against the standard to check for any mistakes or differences.

I also added a comment at the beginning of each case, to more clealry delimit special cases, with a syntax that is easy to read (a mix of C, mathematical language, ...). We may want to use those as tagged paragraphs.

man3/pow.3 +63 -44

207 lines not on this page · raw message

Signature · 4 lines
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.