Mercurial > hg > octave-shane > gnulib-hg
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 |
rev | line source |
---|---|
13977 | 1 /* Test of rounding towards negative infinity. |
17587 | 2 Copyright (C) 2010-2014 Free Software Foundation, Inc. |
13977 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 #include <config.h> | |
18 | |
19 #include <math.h> | |
20 | |
16422
62527036e51c
floorf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
21 #include "isnanf-nolibm.h" |
13977 | 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 | 25 #include "macros.h" |
26 | |
27 /* If IEEE compliance was not requested, the ICC compiler inlines its | |
28 own floorf assembly that turns -0.0f to 0.0f; but that is a correct | |
29 result when IEEE is not enforced. To avoid spurious failure, we | |
30 have to provide this dummy function in order to outsmart ICC's | |
31 inlining, and call our floorf through a function pointer. */ | |
32 static float | |
33 dummy (float f) | |
34 { | |
35 return 0; | |
36 } | |
37 | |
38 int | |
39 main (int argc, char **argv _GL_UNUSED) | |
40 { | |
41 float (*my_floorf) (float) = argc ? floorf : dummy; | |
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 | 48 /* Zero. */ |
49 ASSERT (!signbit (my_floorf (0.0f))); | |
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 | 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 | 66 return 0; |
67 } |