public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* floor/ceil man pages
@ 2026-01-28 14:51 Morten Welinder
  2026-01-29 15:37 ` Alejandro Colomar
  0 siblings, 1 reply; 5+ messages in thread
From: Morten Welinder @ 2026-01-28 14:51 UTC (permalink / raw)
  To: Alejandro Colomar, linux-man

I see two minor problems:

"If x is integral, +0, -0, NaN, or infinite, x itself is returned." --
this seems to suggest that NaN is passed through unchanged, i.e., the
type and sign of the NaN is unchanged.  Other references I can find
suggest that the NaN details are not guaranted.  See
https://en.cppreference.com/w/c/numeric/math/floor.html, for example.

"ceil(-0.5) is 0.0".  I can't find a reference, but (1) this looks
weird, and (2) it looks like libc actually returns -0.0 which makes
more sense.  As noted above, ceil(-0.0) is required to be -0.0 if if
ceil(-0.5) were to return +0.0 it would make ceil a non-monotonic
function.

M.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: floor/ceil man pages
  2026-01-28 14:51 floor/ceil man pages Morten Welinder
@ 2026-01-29 15:37 ` Alejandro Colomar
  2026-01-29 16:27   ` Joseph Myers
  0 siblings, 1 reply; 5+ messages in thread
From: Alejandro Colomar @ 2026-01-29 15:37 UTC (permalink / raw)
  To: Morten Welinder, josmyers; +Cc: linux-man, libc-help

[-- Attachment #1: Type: text/plain, Size: 1169 bytes --]

[TO += Joseph]
[CC += libc-help@]

Hi Morten, Joseph,

On 2026-01-28T09:51:47-0500, Morten Welinder wrote:
> I see two minor problems:
> 
> "If x is integral, +0, -0, NaN, or infinite, x itself is returned." --
> this seems to suggest that NaN is passed through unchanged, i.e., the
> type and sign of the NaN is unchanged.  Other references I can find
> suggest that the NaN details are not guaranted.  See
> https://en.cppreference.com/w/c/numeric/math/floor.html, for example.

Would you mind quoting the specific text that you think suggests that?
I see in that page

	If arg is NaN, NaN is returned.

> "ceil(-0.5) is 0.0".  I can't find a reference, but (1) this looks
> weird, and (2) it looks like libc actually returns -0.0 which makes
> more sense.  As noted above, ceil(-0.0) is required to be -0.0 if if
> ceil(-0.5) were to return +0.0 it would make ceil a non-monotonic
> function.

I have no idea.  It doesn't seem to be specified by the standard.
Joseph, do you know if the floating-point group has talked anything
about this recently?


Have a lovely day!
Alex

> 
> M.
> 

-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: floor/ceil man pages
  2026-01-29 15:37 ` Alejandro Colomar
@ 2026-01-29 16:27   ` Joseph Myers
  2026-01-29 18:08     ` Morten Welinder
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph Myers @ 2026-01-29 16:27 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: Morten Welinder, linux-man, libc-help

On Thu, 29 Jan 2026, Alejandro Colomar wrote:

> > "ceil(-0.5) is 0.0".  I can't find a reference, but (1) this looks
> > weird, and (2) it looks like libc actually returns -0.0 which makes
> > more sense.  As noted above, ceil(-0.0) is required to be -0.0 if if
> > ceil(-0.5) were to return +0.0 it would make ceil a non-monotonic
> > function.
> 
> I have no idea.  It doesn't seem to be specified by the standard.
> Joseph, do you know if the floating-point group has talked anything
> about this recently?

round, floor, ceil, trunc and roundeven (of non-NaN) always return a 
result with the sign of their input, including when that result is zero.  
This is not anything new.

-- 
Joseph S. Myers
josmyers@redhat.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: floor/ceil man pages
  2026-01-29 16:27   ` Joseph Myers
@ 2026-01-29 18:08     ` Morten Welinder
  2026-02-10 23:38       ` Alejandro Colomar
  0 siblings, 1 reply; 5+ messages in thread
From: Morten Welinder @ 2026-01-29 18:08 UTC (permalink / raw)
  To: Joseph Myers; +Cc: Alejandro Colomar, linux-man, libc-help

For NaN, it comes down to the ieee spec.  Ieee-754-2008 in Section 6.3
specifies that the only operations delivering a defined sign for NaNs
are: copy, abs, negate, and copysign.  "For all other operations, this
standard does not specify the sign bit of a NaN result, even when
there is only one input NaN, or when the NaN is produced from an
invalid operation."

The glibc people have in the past defended the freedom to return
whatever sign on NaN they feel like.  See
https://sourceware.org/bugzilla/show_bug.cgi?id=31104 for an example
where float/double/long double versions of various functions disagree
on what sign to return for NaN.

I don't think the man page should promise more than some standard
requires unless the implementation is specifically offering further
guarantees.

M.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: floor/ceil man pages
  2026-01-29 18:08     ` Morten Welinder
@ 2026-02-10 23:38       ` Alejandro Colomar
  0 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar @ 2026-02-10 23:38 UTC (permalink / raw)
  To: Morten Welinder; +Cc: Joseph Myers, linux-man, libc-help

[-- Attachment #1: Type: text/plain, Size: 1042 bytes --]

Hi Morten, Joseph,

On 2026-01-29T13:08:43-0500, Morten Welinder wrote:
> For NaN, it comes down to the ieee spec.  Ieee-754-2008 in Section 6.3
> specifies that the only operations delivering a defined sign for NaNs
> are: copy, abs, negate, and copysign.  "For all other operations, this
> standard does not specify the sign bit of a NaN result, even when
> there is only one input NaN, or when the NaN is produced from an
> invalid operation."
> 
> The glibc people have in the past defended the freedom to return
> whatever sign on NaN they feel like.  See
> https://sourceware.org/bugzilla/show_bug.cgi?id=31104 for an example
> where float/double/long double versions of various functions disagree
> on what sign to return for NaN.
> 
> I don't think the man page should promise more than some standard
> requires unless the implementation is specifically offering further
> guarantees.

Agree.  Would you want to send a patch?


Have a lovely night!
Alex

> 
> M.

-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-10 23:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28 14:51 floor/ceil man pages Morten Welinder
2026-01-29 15:37 ` Alejandro Colomar
2026-01-29 16:27   ` Joseph Myers
2026-01-29 18:08     ` Morten Welinder
2026-02-10 23:38       ` Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox