annotate tests/test-ldexpl.c @ 8590:ebe4e154c5db

Tests for module 'ldexpl'.
author Bruno Haible <bruno@clisp.org>
date Fri, 30 Mar 2007 00:21:34 +0000
parents
children a2bc90a7b7aa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of multiplying a 'long double' by a power of 2.
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 any later version.
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program; if not, write to the Free Software Foundation,
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <config.h>
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <math.h>
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <float.h>
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdlib.h>
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include "fpucw.h"
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include "isnanl-nolibm.h"
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #define ASSERT(expr) if (!(expr)) abort ();
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 int
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 main ()
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 {
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 int i;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 long double x;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 long double y;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 DECL_LONG_DOUBLE_ROUNDING
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 BEGIN_LONG_DOUBLE_ROUNDING ();
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 { /* NaN. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 x = 0.0L / 0.0L;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 y = ldexpl (x, 0); ASSERT (isnanl (y));
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 y = ldexpl (x, 5); ASSERT (isnanl (y));
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 y = ldexpl (x, -5); ASSERT (isnanl (y));
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 { /* Positive infinity. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 x = 1.0L / 0.0L;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 y = ldexpl (x, 5); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 y = ldexpl (x, -5); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 { /* Negative infinity. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 x = -1.0L / 0.0L;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 y = ldexpl (x, 5); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 y = ldexpl (x, -5); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 { /* Positive zero. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 x = 0.0L;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 y = ldexpl (x, 5); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 y = ldexpl (x, -5); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 { /* Negative zero. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 x = -0.0L;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 y = ldexpl (x, 5); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 y = ldexpl (x, -5); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 { /* Positive finite number. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 x = 1.73205L;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 { /* Negative finite number. */
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 x = -20.085536923187667742L;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 for (i = 1, x = 1.73205L; i <= LDBL_MAX_EXP; i++, x *= 2.0L)
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 {
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 for (i = 1, x = 1.73205L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 {
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 if (i - 5 >= LDBL_MIN_EXP)
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 {
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 y = ldexpl (x, -5); ASSERT (y == x * 0.03125L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 for (; i >= LDBL_MIN_EXP - 100 && x > 0.0L; i--, x *= 0.5L)
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 {
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 y = ldexpl (x, 0); ASSERT (y == x);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 y = ldexpl (x, 5); ASSERT (y == x * 32.0L);
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 }
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 return 0;
ebe4e154c5db Tests for module 'ldexpl'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 }