annotate tests/test-roundl.c @ 9375:96fea5b2eb11

Implement 'round', 'roundf', 'roundl' modules.
author Ben Pfaff <blp@cs.stanford.edu>
date Sat, 20 Oct 2007 13:08:26 -0700
parents
children 0be6f1ab456d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9375
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
1 /* Test of rounding to nearest, breaking ties away from zero.
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
3
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
7 any later version.
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
8
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
12 GNU General Public License for more details.
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
13
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
17
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
18 /* Written by Ben Pfaff <blp@gnu.org>, 2007.
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
19 Based heavily on Bruno Haible's test-truncl.c. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
20
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
21 #include <config.h>
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
22
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
23 #include <math.h>
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
24
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
25 #include <stdio.h>
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
26 #include <stdlib.h>
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
27
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
28 #include "fpucw.h"
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
29 #include "isnanl-nolibm.h"
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
30
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
31 #define ASSERT(expr) \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
32 do \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
33 { \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
34 if (!(expr)) \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
35 { \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
36 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
37 abort (); \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
38 } \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
39 } \
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
40 while (0)
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
41
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
42 int
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
43 main ()
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
44 {
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
45 DECL_LONG_DOUBLE_ROUNDING
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
46
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
47 BEGIN_LONG_DOUBLE_ROUNDING ();
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
48
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
49 /* Zero. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
50 ASSERT (roundl (0.0L) == 0.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
51 ASSERT (roundl (-0.0L) == 0.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
52 /* Positive numbers. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
53 ASSERT (roundl (0.3L) == 0.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
54 ASSERT (roundl (0.5L) == 1.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
55 ASSERT (roundl (0.7L) == 1.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
56 ASSERT (roundl (1.0L) == 1.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
57 ASSERT (roundl (1.5L) == 2.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
58 ASSERT (roundl (2.5L) == 3.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
59 ASSERT (roundl (1.999L) == 2.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
60 ASSERT (roundl (2.0L) == 2.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
61 ASSERT (roundl (65535.999L) == 65536.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
62 ASSERT (roundl (65536.0L) == 65536.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
63 ASSERT (roundl (65536.001L) == 65536.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
64 ASSERT (roundl (2.341e31L) == 2.341e31L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
65 /* Negative numbers. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
66 ASSERT (roundl (-0.3L) == 0.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
67 ASSERT (roundl (-0.5L) == -1.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
68 ASSERT (roundl (-0.7L) == -1.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
69 ASSERT (roundl (-1.0L) == -1.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
70 ASSERT (roundl (-1.5L) == -2.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
71 ASSERT (roundl (-2.5L) == -3.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
72 ASSERT (roundl (-1.999L) == -2.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
73 ASSERT (roundl (-2.0L) == -2.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
74 ASSERT (roundl (-65535.999L) == -65536.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
75 ASSERT (roundl (-65536.0L) == -65536.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
76 ASSERT (roundl (-65536.001L) == -65536.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
77 ASSERT (roundl (-2.341e31L) == -2.341e31L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
78 /* Infinite numbers. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
79 ASSERT (roundl (1.0 / 0.0L) == 1.0 / 0.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
80 ASSERT (roundl (-1.0 / 0.0L) == -1.0 / 0.0L);
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
81 /* NaNs. */
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
82 ASSERT (isnanl (roundl (0.0L / 0.0L)));
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
83
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
84 return 0;
96fea5b2eb11 Implement 'round', 'roundf', 'roundl' modules.
Ben Pfaff <blp@cs.stanford.edu>
parents:
diff changeset
85 }