[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: floor, ceil, trunc, round, minus zero, and alpha
From: |
Eric Blake |
Subject: |
Re: floor, ceil, trunc, round, minus zero, and alpha |
Date: |
Mon, 20 Dec 2010 14:08:08 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.7 |
On 12/20/2010 08:44 AM, Bruno Haible wrote:
> Eric Blake wrote:
>>> - are marked as [MX] in POSIX [1][2][3][4], that is, an optional feature
>>> not contained in ISO C 99,
>>
>> [MX] means that the behavior is required on platforms that claim IEC
>> 60559 conformance (aka IEEE 754 format); it means that you fully
>> implement the otherwise-optional Appendix F of the C99 standard.
>
> I see. Thanks for correcting me.
>
> Regarding DEC Alpha platforms, I don't think they are 100% IEEE 754 + 854
> compliant, because the hardware designers took some shortcuts regarding
> the exception handling, in order to implement the floating-point operations
> in a single CPU cycle.
>
>>> - make little sense for 'ceil' from a mathematical point of view:
>>> ceil is a monotonically increasing function but POSIX wants
>>> ceil(-0.5) = 0.0 and ceil(-0.0) = -0.0,
>>
>> I'll raise that point with the Austin group.
>
> Given that the annex section F.9.6.1 in ISO C99 already specifies this
> behaviour, I don't think the Austin group will deviate from that.
Fred Tydeman pointed out that since POSIX [MX] shading defers to C99
Appendix F, which defers to IEEE 754, and IEEE 754 section 6.3 The Sign
Bit states:
... and the sign of the result of the round floating-point number to
integral value operation is the sign of the operand. These rules shall
apply even when operands or results are zero or infinite.
Therefore, POSIX requires ceil(-0.5) to return -0.0 when you are
strictly compliant (if you actually tested a system where it returns
+0.0, you found a bug, but the bug is only worth fixing if we care about
ieee-fp).
And indeed, glibc gives ieee-compliant behavior:
$ cat foo.c
#include <math.h>
#include <stdio.h>
int main (void)
{
printf ("%d %d\n", signbit(ceil(-0.5)), signbit(ceil(0.5)));
return 0;
}
$ gcc -o foo -Wall -g foo.c -lm
$ ./foo
128 0
--
Eric Blake address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- floor, ceil, trunc, round, minus zero, and alpha, Bruno Haible, 2010/12/20
- Re: floor, ceil, trunc, round, minus zero, and alpha, Eric Blake, 2010/12/20
- Re: floor, ceil, trunc, round, minus zero, and alpha, Bruno Haible, 2010/12/20
- Re: floor, ceil, trunc, round, minus zero, and alpha, Eric Blake, 2010/12/20
- Re: floor, ceil, trunc, round, minus zero, and alpha, Bruno Haible, 2010/12/20
- Re: floor, ceil, trunc, round, minus zero, and alpha, Paul Eggert, 2010/12/20
- Re: floor, ceil, trunc, round, minus zero, and alpha, Bruno Haible, 2010/12/20
- Re: floor, ceil, trunc, round, minus zero, and alpha, Bruno Haible, 2010/12/22
- Re: floor, ceil, trunc, round, minus zero, and alpha,
Eric Blake <=
- Re: floor, ceil, trunc, round, minus zero, and alpha, Bruno Haible, 2010/12/22
- Prev by Date:
Re: floor, ceil, trunc, round, minus zero, and alpha
- Next by Date:
Re: floor, ceil, trunc, round, minus zero, and alpha
- Previous by thread:
Re: floor, ceil, trunc, round, minus zero, and alpha
- Next by thread:
Re: floor, ceil, trunc, round, minus zero, and alpha
- Index(es):