comparison 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
comparison
equal deleted inserted replaced
9374:f3d25691c7ac 9375:96fea5b2eb11
1 /* Test of rounding to nearest, breaking ties away from zero.
2 Copyright (C) 2007 Free Software Foundation, Inc.
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 2, 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
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17
18 /* Written by Ben Pfaff <blp@gnu.org>, 2007.
19 Based heavily on Bruno Haible's test-truncl.c. */
20
21 #include <config.h>
22
23 #include <math.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #include "fpucw.h"
29 #include "isnanl-nolibm.h"
30
31 #define ASSERT(expr) \
32 do \
33 { \
34 if (!(expr)) \
35 { \
36 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
37 abort (); \
38 } \
39 } \
40 while (0)
41
42 int
43 main ()
44 {
45 DECL_LONG_DOUBLE_ROUNDING
46
47 BEGIN_LONG_DOUBLE_ROUNDING ();
48
49 /* Zero. */
50 ASSERT (roundl (0.0L) == 0.0L);
51 ASSERT (roundl (-0.0L) == 0.0L);
52 /* Positive numbers. */
53 ASSERT (roundl (0.3L) == 0.0L);
54 ASSERT (roundl (0.5L) == 1.0L);
55 ASSERT (roundl (0.7L) == 1.0L);
56 ASSERT (roundl (1.0L) == 1.0L);
57 ASSERT (roundl (1.5L) == 2.0L);
58 ASSERT (roundl (2.5L) == 3.0L);
59 ASSERT (roundl (1.999L) == 2.0L);
60 ASSERT (roundl (2.0L) == 2.0L);
61 ASSERT (roundl (65535.999L) == 65536.0L);
62 ASSERT (roundl (65536.0L) == 65536.0L);
63 ASSERT (roundl (65536.001L) == 65536.0L);
64 ASSERT (roundl (2.341e31L) == 2.341e31L);
65 /* Negative numbers. */
66 ASSERT (roundl (-0.3L) == 0.0L);
67 ASSERT (roundl (-0.5L) == -1.0L);
68 ASSERT (roundl (-0.7L) == -1.0L);
69 ASSERT (roundl (-1.0L) == -1.0L);
70 ASSERT (roundl (-1.5L) == -2.0L);
71 ASSERT (roundl (-2.5L) == -3.0L);
72 ASSERT (roundl (-1.999L) == -2.0L);
73 ASSERT (roundl (-2.0L) == -2.0L);
74 ASSERT (roundl (-65535.999L) == -65536.0L);
75 ASSERT (roundl (-65536.0L) == -65536.0L);
76 ASSERT (roundl (-65536.001L) == -65536.0L);
77 ASSERT (roundl (-2.341e31L) == -2.341e31L);
78 /* Infinite numbers. */
79 ASSERT (roundl (1.0 / 0.0L) == 1.0 / 0.0L);
80 ASSERT (roundl (-1.0 / 0.0L) == -1.0 / 0.0L);
81 /* NaNs. */
82 ASSERT (isnanl (roundl (0.0L / 0.0L)));
83
84 return 0;
85 }