Mercurial > gnulib
annotate tests/test-roundf-ieee.c @ 40196:e63f5d3edab5
relocatable-prog: Update documentation.
* doc/relocatable-maint.texi (Supporting Relocation): Update to match
the recent changes.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 24 Feb 2019 01:49:15 +0100 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
13980 | 1 /* Test of rounding to nearest, breaking ties away from zero. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
2 Copyright (C) 2010-2019 Free Software Foundation, Inc. |
13980 | 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, or (at your option) | |
7 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 | |
19190 | 15 along with this program; if not, see <https://www.gnu.org/licenses/>. */ |
13980 | 16 |
17 #include <config.h> | |
18 | |
19 #include <math.h> | |
20 | |
16431
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
21 #include "isnanf-nolibm.h" |
13980 | 22 #include "minus-zero.h" |
16431
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
23 #include "infinity.h" |
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
24 #include "nan.h" |
13980 | 25 #include "macros.h" |
26 | |
27 int | |
28 main () | |
29 { | |
13994
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
30 /* See IEEE 754, section 6.3: |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
31 "the sign of the result of the round floating-point number to |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
32 integral value operation is the sign of the operand. These rules |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
33 shall apply even when operands or results are zero or infinite." */ |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
34 |
13980 | 35 /* Zero. */ |
36 ASSERT (!signbit (roundf (0.0f))); | |
37 ASSERT (!!signbit (roundf (minus_zerof)) == !!signbit (minus_zerof)); | |
13994
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
38 /* Positive numbers. */ |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
39 ASSERT (!signbit (roundf (0.3f))); |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
40 ASSERT (!signbit (roundf (0.7f))); |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
41 /* Negative numbers. */ |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
42 ASSERT (!!signbit (roundf (-0.3f)) == !!signbit (minus_zerof)); |
b91bc81df379
round: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents:
13980
diff
changeset
|
43 ASSERT (!!signbit (roundf (-0.7f)) == !!signbit (minus_zerof)); |
13980 | 44 |
16431
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
45 /* [MX] shaded specification in POSIX. */ |
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
46 |
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
47 /* NaN. */ |
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
48 ASSERT (isnanf (roundf (NaNf ()))); |
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
49 /* Infinity. */ |
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
50 ASSERT (roundf (Infinityf ()) == Infinityf ()); |
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
51 ASSERT (roundf (- Infinityf ()) == - Infinityf ()); |
f16e87d6bf2e
roundf-ieee tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
16366
diff
changeset
|
52 |
13980 | 53 return 0; |
54 } |