Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 1 | //===-- powixf2_test.cpp - Test __powixf2 ---------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | 9ad441f | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file tests __powixf2 for the compiler_rt library. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #if !_ARCH_PPC |
| 15 | |
| 16 | #include "int_lib.h" |
| 17 | #include <stdio.h> |
| 18 | #include <math.h> |
| 19 | |
| 20 | // Returns: a ^ b |
| 21 | |
| 22 | long double __powixf2(long double a, si_int b); |
| 23 | |
| 24 | int test__powixf2(long double a, si_int b, long double expected) |
| 25 | { |
| 26 | long double x = __powixf2(a, b); |
| 27 | int correct = (x == expected) && (signbit(x) == signbit(expected)); |
| 28 | if (!correct) |
| 29 | printf("error in __powixf2(%Lf, %d) = %Lf, expected %Lf\n", |
| 30 | a, b, x, expected); |
| 31 | return !correct; |
| 32 | } |
| 33 | |
| 34 | #endif |
| 35 | |
| 36 | int main() |
| 37 | { |
| 38 | #if !_ARCH_PPC |
| 39 | if (test__powixf2(0, 0, 1)) |
| 40 | return 1; |
| 41 | if (test__powixf2(1, 0, 1)) |
| 42 | return 1; |
| 43 | if (test__powixf2(1.5, 0, 1)) |
| 44 | return 1; |
| 45 | if (test__powixf2(2, 0, 1)) |
| 46 | return 1; |
| 47 | if (test__powixf2(INFINITY, 0, 1)) |
| 48 | return 1; |
| 49 | |
| 50 | if (test__powixf2(-0., 0, 1)) |
| 51 | return 1; |
| 52 | if (test__powixf2(-1, 0, 1)) |
| 53 | return 1; |
| 54 | if (test__powixf2(-1.5, 0, 1)) |
| 55 | return 1; |
| 56 | if (test__powixf2(-2, 0, 1)) |
| 57 | return 1; |
| 58 | if (test__powixf2(-INFINITY, 0, 1)) |
| 59 | return 1; |
| 60 | |
| 61 | if (test__powixf2(0, 1, 0)) |
| 62 | return 1; |
| 63 | if (test__powixf2(0, 2, 0)) |
| 64 | return 1; |
| 65 | if (test__powixf2(0, 3, 0)) |
| 66 | return 1; |
| 67 | if (test__powixf2(0, 4, 0)) |
| 68 | return 1; |
| 69 | if (test__powixf2(0, 0x7FFFFFFE, 0)) |
| 70 | return 1; |
| 71 | if (test__powixf2(0, 0x7FFFFFFF, 0)) |
| 72 | return 1; |
| 73 | |
| 74 | if (test__powixf2(-0., 1, -0.)) |
| 75 | return 1; |
| 76 | if (test__powixf2(-0., 2, 0)) |
| 77 | return 1; |
| 78 | if (test__powixf2(-0., 3, -0.)) |
| 79 | return 1; |
| 80 | if (test__powixf2(-0., 4, 0)) |
| 81 | return 1; |
| 82 | if (test__powixf2(-0., 0x7FFFFFFE, 0)) |
| 83 | return 1; |
| 84 | if (test__powixf2(-0., 0x7FFFFFFF, -0.)) |
| 85 | return 1; |
| 86 | |
| 87 | if (test__powixf2(1, 1, 1)) |
| 88 | return 1; |
| 89 | if (test__powixf2(1, 2, 1)) |
| 90 | return 1; |
| 91 | if (test__powixf2(1, 3, 1)) |
| 92 | return 1; |
| 93 | if (test__powixf2(1, 4, 1)) |
| 94 | return 1; |
| 95 | if (test__powixf2(1, 0x7FFFFFFE, 1)) |
| 96 | return 1; |
| 97 | if (test__powixf2(1, 0x7FFFFFFF, 1)) |
| 98 | return 1; |
| 99 | |
| 100 | if (test__powixf2(INFINITY, 1, INFINITY)) |
| 101 | return 1; |
| 102 | if (test__powixf2(INFINITY, 2, INFINITY)) |
| 103 | return 1; |
| 104 | if (test__powixf2(INFINITY, 3, INFINITY)) |
| 105 | return 1; |
| 106 | if (test__powixf2(INFINITY, 4, INFINITY)) |
| 107 | return 1; |
| 108 | if (test__powixf2(INFINITY, 0x7FFFFFFE, INFINITY)) |
| 109 | return 1; |
| 110 | if (test__powixf2(INFINITY, 0x7FFFFFFF, INFINITY)) |
| 111 | return 1; |
| 112 | |
| 113 | if (test__powixf2(-INFINITY, 1, -INFINITY)) |
| 114 | return 1; |
| 115 | if (test__powixf2(-INFINITY, 2, INFINITY)) |
| 116 | return 1; |
| 117 | if (test__powixf2(-INFINITY, 3, -INFINITY)) |
| 118 | return 1; |
| 119 | if (test__powixf2(-INFINITY, 4, INFINITY)) |
| 120 | return 1; |
| 121 | if (test__powixf2(-INFINITY, 0x7FFFFFFE, INFINITY)) |
| 122 | return 1; |
| 123 | if (test__powixf2(-INFINITY, 0x7FFFFFFF, -INFINITY)) |
| 124 | return 1; |
| 125 | |
| 126 | if (test__powixf2(0, -1, INFINITY)) |
| 127 | return 1; |
| 128 | if (test__powixf2(0, -2, INFINITY)) |
| 129 | return 1; |
| 130 | if (test__powixf2(0, -3, INFINITY)) |
| 131 | return 1; |
| 132 | if (test__powixf2(0, -4, INFINITY)) |
| 133 | return 1; |
| 134 | if (test__powixf2(0, 0x80000002, INFINITY)) |
| 135 | return 1; |
| 136 | if (test__powixf2(0, 0x80000001, INFINITY)) |
| 137 | return 1; |
| 138 | if (test__powixf2(0, 0x80000000, INFINITY)) |
| 139 | return 1; |
| 140 | |
| 141 | if (test__powixf2(-0., -1, -INFINITY)) |
| 142 | return 1; |
| 143 | if (test__powixf2(-0., -2, INFINITY)) |
| 144 | return 1; |
| 145 | if (test__powixf2(-0., -3, -INFINITY)) |
| 146 | return 1; |
| 147 | if (test__powixf2(-0., -4, INFINITY)) |
| 148 | return 1; |
| 149 | if (test__powixf2(-0., 0x80000002, INFINITY)) |
| 150 | return 1; |
| 151 | if (test__powixf2(-0., 0x80000001, -INFINITY)) |
| 152 | return 1; |
| 153 | if (test__powixf2(-0., 0x80000000, INFINITY)) |
| 154 | return 1; |
| 155 | |
| 156 | if (test__powixf2(1, -1, 1)) |
| 157 | return 1; |
| 158 | if (test__powixf2(1, -2, 1)) |
| 159 | return 1; |
| 160 | if (test__powixf2(1, -3, 1)) |
| 161 | return 1; |
| 162 | if (test__powixf2(1, -4, 1)) |
| 163 | return 1; |
| 164 | if (test__powixf2(1, 0x80000002, 1)) |
| 165 | return 1; |
| 166 | if (test__powixf2(1, 0x80000001, 1)) |
| 167 | return 1; |
| 168 | if (test__powixf2(1, 0x80000000, 1)) |
| 169 | return 1; |
| 170 | |
| 171 | if (test__powixf2(INFINITY, -1, 0)) |
| 172 | return 1; |
| 173 | if (test__powixf2(INFINITY, -2, 0)) |
| 174 | return 1; |
| 175 | if (test__powixf2(INFINITY, -3, 0)) |
| 176 | return 1; |
| 177 | if (test__powixf2(INFINITY, -4, 0)) |
| 178 | return 1; |
| 179 | if (test__powixf2(INFINITY, 0x80000002, 0)) |
| 180 | return 1; |
| 181 | if (test__powixf2(INFINITY, 0x80000001, 0)) |
| 182 | return 1; |
| 183 | if (test__powixf2(INFINITY, 0x80000000, 0)) |
| 184 | return 1; |
| 185 | |
| 186 | if (test__powixf2(-INFINITY, -1, -0.)) |
| 187 | return 1; |
| 188 | if (test__powixf2(-INFINITY, -2, 0)) |
| 189 | return 1; |
| 190 | if (test__powixf2(-INFINITY, -3, -0.)) |
| 191 | return 1; |
| 192 | if (test__powixf2(-INFINITY, -4, 0)) |
| 193 | return 1; |
| 194 | if (test__powixf2(-INFINITY, 0x80000002, 0)) |
| 195 | return 1; |
| 196 | if (test__powixf2(-INFINITY, 0x80000001, -0.)) |
| 197 | return 1; |
| 198 | if (test__powixf2(-INFINITY, 0x80000000, 0)) |
| 199 | return 1; |
| 200 | |
| 201 | if (test__powixf2(2, 10, 1024.)) |
| 202 | return 1; |
| 203 | if (test__powixf2(-2, 10, 1024.)) |
| 204 | return 1; |
| 205 | if (test__powixf2(2, -10, 1/1024.)) |
| 206 | return 1; |
| 207 | if (test__powixf2(-2, -10, 1/1024.)) |
| 208 | return 1; |
| 209 | |
| 210 | if (test__powixf2(2, 19, 524288.)) |
| 211 | return 1; |
| 212 | if (test__powixf2(-2, 19, -524288.)) |
| 213 | return 1; |
| 214 | if (test__powixf2(2, -19, 1/524288.)) |
| 215 | return 1; |
| 216 | if (test__powixf2(-2, -19, -1/524288.)) |
| 217 | return 1; |
| 218 | |
| 219 | if (test__powixf2(2, 31, 2147483648.)) |
| 220 | return 1; |
| 221 | if (test__powixf2(-2, 31, -2147483648.)) |
| 222 | return 1; |
| 223 | if (test__powixf2(2, -31, 1/2147483648.)) |
| 224 | return 1; |
| 225 | if (test__powixf2(-2, -31, -1/2147483648.)) |
| 226 | return 1; |
| 227 | |
Joerg Sonnenberger | 7482815 | 2011-05-29 21:43:29 +0000 | [diff] [blame] | 228 | #else |
| 229 | printf("skipped\n"); |
Daniel Dunbar | b3a6901 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 230 | #endif |
| 231 | return 0; |
| 232 | } |