Mercurial > gnulib
annotate tests/test-truncf1.c @ 29987:7bf583f1e789
Work around bug of HP-UX 10.20 cc with -0.0 literal.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 01 Aug 2008 11:30:27 +0200 |
parents | e4b084d57f9e |
children | e8d2c6fc33ad |
rev | line source |
---|---|
29016
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Test of rounding towards zero. |
29545
b33f34454211
Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents:
29541
diff
changeset
|
2 Copyright (C) 2007-2008 Free Software Foundation, Inc. |
29016
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
3 |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 (at your option) any later version. |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #include <config.h> |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 #include <math.h> |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 #include <stdio.h> |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include <stdlib.h> |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 |
29955
e4b084d57f9e
Rename isnand.h to isnand-nolibm.h, similarly for isnanf.h.
Ben Pfaff <blp@cs.stanford.edu>
parents:
29580
diff
changeset
|
26 #include "isnanf-nolibm.h" |
29545
b33f34454211
Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents:
29541
diff
changeset
|
27 #include "nan.h" |
29071
e3476e081c79
Use isnanf() instead of isnan(). Avoids a link error on HP-UX 11.
Bruno Haible <bruno@clisp.org>
parents:
29016
diff
changeset
|
28 |
29016
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 #define ASSERT(expr) \ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 do \ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 { \ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 if (!(expr)) \ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 { \ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ |
29580
f6378ee83796
Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents:
29545
diff
changeset
|
35 fflush (stderr); \ |
29016
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 abort (); \ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 } \ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 } \ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 while (0) |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 |
29987
7bf583f1e789
Work around bug of HP-UX 10.20 cc with -0.0 literal.
Bruno Haible <bruno@clisp.org>
parents:
29955
diff
changeset
|
41 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0f. |
7bf583f1e789
Work around bug of HP-UX 10.20 cc with -0.0 literal.
Bruno Haible <bruno@clisp.org>
parents:
29955
diff
changeset
|
42 So we use -zero instead. */ |
7bf583f1e789
Work around bug of HP-UX 10.20 cc with -0.0 literal.
Bruno Haible <bruno@clisp.org>
parents:
29955
diff
changeset
|
43 float zero = 0.0f; |
7bf583f1e789
Work around bug of HP-UX 10.20 cc with -0.0 literal.
Bruno Haible <bruno@clisp.org>
parents:
29955
diff
changeset
|
44 |
29016
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 int |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 main () |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
47 { |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 /* Zero. */ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 ASSERT (truncf (0.0f) == 0.0f); |
29987
7bf583f1e789
Work around bug of HP-UX 10.20 cc with -0.0 literal.
Bruno Haible <bruno@clisp.org>
parents:
29955
diff
changeset
|
50 ASSERT (truncf (-zero) == 0.0f); |
29016
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 /* Positive numbers. */ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 ASSERT (truncf (0.3f) == 0.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
53 ASSERT (truncf (0.7f) == 0.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 ASSERT (truncf (1.0f) == 1.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 ASSERT (truncf (1.5f) == 1.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 ASSERT (truncf (1.999f) == 1.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 ASSERT (truncf (2.0f) == 2.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 ASSERT (truncf (65535.99f) == 65535.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 ASSERT (truncf (65536.0f) == 65536.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 ASSERT (truncf (2.341e31f) == 2.341e31f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
61 /* Negative numbers. */ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 ASSERT (truncf (-0.3f) == 0.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
63 ASSERT (truncf (-0.7f) == 0.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 ASSERT (truncf (-1.0f) == -1.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 ASSERT (truncf (-1.5f) == -1.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 ASSERT (truncf (-1.999f) == -1.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 ASSERT (truncf (-2.0f) == -2.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 ASSERT (truncf (-65535.99f) == -65535.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 ASSERT (truncf (-65536.0f) == -65536.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 ASSERT (truncf (-2.341e31f) == -2.341e31f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 /* Infinite numbers. */ |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 ASSERT (truncf (1.0f / 0.0f) == 1.0f / 0.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 ASSERT (truncf (-1.0f / 0.0f) == -1.0f / 0.0f); |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 /* NaNs. */ |
29545
b33f34454211
Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents:
29541
diff
changeset
|
75 ASSERT (isnanf (truncf (NaNf ()))); |
29016
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 return 0; |
00b003f393d6
Rename test-truncf.c to test-truncf1.c.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 } |