annotate tests/test-floorf-ieee.c @ 17632:86af85d364e1 default tip

unistd: port readlink to Mac OS X 10.3.9 * lib/unistd.in.h (_GL_INCLUDING_UNISTD_H): New macro, to work around self-include problem in Mac OS X 10.3.9 when combined with readlink module. Problem reported by Klaus Zietler in <http://bugs.gnu.org/16825>.
author Paul Eggert <eggert@penguin.cs.ucla.edu>
date Tue, 25 Feb 2014 11:16:27 -0800
parents 344018b6e5d7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13977
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of rounding towards negative infinity.
17587
344018b6e5d7 maint: update copyright
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
2 Copyright (C) 2010-2014 Free Software Foundation, Inc.
13977
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <math.h>
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
16422
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
21 #include "isnanf-nolibm.h"
13977
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include "minus-zero.h"
16422
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
23 #include "infinity.h"
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
24 #include "nan.h"
13977
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include "macros.h"
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 /* If IEEE compliance was not requested, the ICC compiler inlines its
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 own floorf assembly that turns -0.0f to 0.0f; but that is a correct
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 result when IEEE is not enforced. To avoid spurious failure, we
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 have to provide this dummy function in order to outsmart ICC's
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 inlining, and call our floorf through a function pointer. */
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 static float
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 dummy (float f)
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 {
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 return 0;
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 }
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 int
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 main (int argc, char **argv _GL_UNUSED)
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 float (*my_floorf) (float) = argc ? floorf : dummy;
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
13991
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
43 /* See IEEE 754, section 6.3:
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
44 "the sign of the result of the round floating-point number to
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
45 integral value operation is the sign of the operand. These rules
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
46 shall apply even when operands or results are zero or infinite." */
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
47
13977
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 /* Zero. */
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 ASSERT (!signbit (my_floorf (0.0f)));
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 ASSERT (!!signbit (my_floorf (minus_zerof)) == !!signbit (minus_zerof));
13991
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
51 /* Positive numbers. */
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
52 ASSERT (!signbit (my_floorf (0.3f)));
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
53 ASSERT (!signbit (my_floorf (0.7f)));
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
54 /* Negative numbers. */
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
55 ASSERT (!!signbit (my_floorf (-0.3f)) == !!signbit (minus_zerof));
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13977
diff changeset
56 ASSERT (!!signbit (my_floorf (-0.7f)) == !!signbit (minus_zerof));
13977
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
16422
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
58 /* [MX] shaded specification in POSIX. */
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
59
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
60 /* NaN. */
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
61 ASSERT (isnanf (floorf (NaNf ())));
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
62 /* Infinity. */
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
63 ASSERT (floorf (Infinityf ()) == Infinityf ());
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
64 ASSERT (floorf (- Infinityf ()) == - Infinityf ());
62527036e51c floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
65
13977
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 return 0;
dcd86f222143 New module 'floorf-ieee'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 }