Mercurial > ecos
annotate packages/language/c/libm/current/src/misc/standard.c @ 2729:74dbf4c3f2e1 after-copyright-change-20090129
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
| author | jlarmour |
|---|---|
| date | Thu, 29 Jan 2009 17:47:46 +0000 |
| parents | d2c90368aeef |
| children | 77f9d3253c3e |
| rev | line source |
|---|---|
| 0 | 1 //=========================================================================== |
| 2 // | |
| 3 // signgam.cxx | |
| 4 // | |
| 5 // Support sign of the gamma*() functions in Math library | |
| 6 // | |
| 7 //=========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
16 // version. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
21 // for more details. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
33 // General Public License v2. |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
210
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 0 | 39 //=========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 2 | 42 // Author(s): jlarmour |
| 43 // Contributors: jlarmour | |
| 0 | 44 // Date: 1998-02-13 |
| 45 // Purpose: | |
| 46 // Description: Contains the accessor functions to get and set the stored sign | |
| 47 // of the gamma*() functions in the math library | |
| 48 // Usage: | |
| 49 // | |
| 50 //####DESCRIPTIONEND#### | |
| 51 // | |
| 52 //=========================================================================== | |
| 53 | |
| 54 /* @(#)k_standard.c 1.3 95/01/18 */ | |
| 55 /* | |
| 56 * ==================================================== | |
| 57 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | |
| 58 * | |
| 59 * Developed at SunSoft, a Sun Microsystems, Inc. business. | |
| 60 * Permission to use, copy, modify, and distribute this | |
| 61 * software is freely granted, provided that this notice | |
| 62 * is preserved. | |
| 63 * ==================================================== | |
| 64 * | |
| 65 */ | |
| 66 | |
| 67 // CONFIGURATION | |
| 68 | |
| 69 #include <pkgconf/libm.h> // Configuration header | |
| 70 | |
| 71 // Include the Math library? | |
| 72 #ifdef CYGPKG_LIBM | |
| 73 | |
| 74 // INCLUDES | |
| 75 | |
| 76 #include <cyg/infra/cyg_type.h> // Common type definitions and support | |
| 77 #include <cyg/infra/cyg_trac.h> // Tracing macros | |
| 78 | |
| 79 #include <math.h> // Main header for math library | |
| 80 #include "mathincl/fdlibm.h" // Internal header for math library | |
| 81 | |
| 82 #include <cyg/error/codes.h> // standard error codes | |
| 83 | |
| 84 #ifndef CYGSEM_LIBM_COMPAT_IEEE_ONLY | |
| 85 #include <errno.h> | |
| 86 #else | |
| 87 static int errno; // this whole file won't be used if we're IEEE only, but | |
| 88 // doing this keeps the compiler happy | |
| 89 #endif | |
| 90 | |
| 91 #ifdef CYGSEM_LIBM_USE_STDERR | |
| 92 | |
| 93 #include <stdio.h> | |
| 94 #define WRITE2(u,v) fputs(u, stderr) | |
| 95 | |
| 96 #else | |
| 97 | |
| 98 #define WRITE2(u,v) 0 | |
| 99 | |
| 100 #endif // ifdef CYGSEM_LIBM_USE_STDERR | |
| 101 | |
| 102 | |
| 103 // GLOBALS | |
| 104 | |
| 105 static const double zero = 0.0; | |
| 106 | |
| 107 // FUNCTIONS | |
| 108 | |
| 109 /* | |
| 110 * Standard conformance (non-IEEE) on exception cases. | |
| 111 * Mapping: | |
| 112 * 1 -- acos(|x|>1) | |
| 113 * 2 -- asin(|x|>1) | |
| 114 * 3 -- atan2(+-0,+-0) | |
| 115 * 4 -- hypot overflow | |
| 116 * 5 -- cosh overflow | |
| 117 * 6 -- exp overflow | |
| 118 * 7 -- exp underflow | |
| 119 * 8 -- y0(0) | |
| 120 * 9 -- y0(-ve) | |
| 121 * 10-- y1(0) | |
| 122 * 11-- y1(-ve) | |
| 123 * 12-- yn(0) | |
| 124 * 13-- yn(-ve) | |
| 125 * 14-- lgamma(finite) overflow | |
| 126 * 15-- lgamma(-integer) | |
| 127 * 16-- log(0) | |
| 128 * 17-- log(x<0) | |
| 129 * 18-- log10(0) | |
| 130 * 19-- log10(x<0) | |
| 131 * 20-- pow(0.0,0.0) | |
| 132 * 21-- pow(x,y) overflow | |
| 133 * 22-- pow(x,y) underflow | |
| 134 * 23-- pow(0,negative) | |
| 135 * 24-- pow(neg,non-integral) | |
| 136 * 25-- sinh(finite) overflow | |
| 137 * 26-- sqrt(negative) | |
| 138 * 27-- fmod(x,0) | |
| 139 * 28-- remainder(x,0) | |
| 140 * 29-- acosh(x<1) | |
| 141 * 30-- atanh(|x|>1) | |
| 142 * 31-- atanh(|x|=1) | |
| 143 * 32-- scalb overflow | |
| 144 * 33-- scalb underflow | |
| 145 * 34-- j0(|x|>X_TLOSS) | |
| 146 * 35-- y0(x>X_TLOSS) | |
| 147 * 36-- j1(|x|>X_TLOSS) | |
| 148 * 37-- y1(x>X_TLOSS) | |
| 149 * 38-- jn(|x|>X_TLOSS, n) | |
| 150 * 39-- yn(x>X_TLOSS, n) | |
| 151 * 40-- gamma(finite) overflow | |
| 152 * 41-- gamma(-integer) | |
| 153 * 42-- pow(NaN,0.0) | |
| 154 * 43-- ldexp overflow | |
| 155 * 44-- ldexp underflow | |
| 156 */ | |
| 157 | |
| 158 | |
| 159 double | |
| 160 __kernel_standard(double x, double y, int type) | |
| 161 { | |
| 162 struct exception exc; | |
| 163 | |
| 164 #ifdef CYGSEM_LIBM_USE_STDERR | |
| 165 (void) fflush(stdout); | |
| 166 #endif | |
| 167 exc.arg1 = x; | |
| 168 exc.arg2 = y; | |
| 169 switch(type) { | |
| 170 case 1: | |
| 171 /* acos(|x|>1) */ | |
| 172 exc.type = DOMAIN; | |
| 173 exc.name = "acos"; | |
| 174 exc.retval = zero; | |
| 175 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 176 errno = EDOM; | |
| 177 else if (!matherr(&exc)) { | |
| 178 if(cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 179 (void) WRITE2("acos: DOMAIN error\n", 19); | |
| 180 } | |
| 181 errno = EDOM; | |
| 182 } | |
| 183 break; | |
| 184 case 2: | |
| 185 /* asin(|x|>1) */ | |
| 186 exc.type = DOMAIN; | |
| 187 exc.name = "asin"; | |
| 188 exc.retval = zero; | |
| 189 if(cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 190 errno = EDOM; | |
| 191 else if (!matherr(&exc)) { | |
| 192 if(cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 193 (void) WRITE2("asin: DOMAIN error\n", 19); | |
| 194 } | |
| 195 errno = EDOM; | |
| 196 } | |
| 197 break; | |
| 198 case 3: | |
| 199 /* atan2(+-0,+-0) */ | |
| 200 exc.arg1 = y; | |
| 201 exc.arg2 = x; | |
| 202 exc.type = DOMAIN; | |
| 203 exc.name = "atan2"; | |
| 204 exc.retval = zero; | |
| 205 if(cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 206 errno = EDOM; | |
| 207 else if (!matherr(&exc)) { | |
| 208 if(cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 209 (void) WRITE2("atan2: DOMAIN error\n", 20); | |
| 210 } | |
| 211 errno = EDOM; | |
| 212 } | |
| 213 break; | |
| 214 case 4: | |
| 215 /* hypot(finite,finite) overflow */ | |
| 216 exc.type = OVERFLOW; | |
| 217 exc.name = "hypot"; | |
| 218 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 219 exc.retval = HUGE; | |
| 220 else | |
| 221 exc.retval = HUGE_VAL; | |
| 222 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 223 errno = ERANGE; | |
| 224 else if (!matherr(&exc)) { | |
| 225 errno = ERANGE; | |
| 226 } | |
| 227 break; | |
| 228 case 5: | |
| 229 /* cosh(finite) overflow */ | |
| 230 exc.type = OVERFLOW; | |
| 231 exc.name = "cosh"; | |
| 232 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 233 exc.retval = HUGE; | |
| 234 else | |
| 235 exc.retval = HUGE_VAL; | |
| 236 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 237 errno = ERANGE; | |
| 238 else if (!matherr(&exc)) { | |
| 239 errno = ERANGE; | |
| 240 } | |
| 241 break; | |
| 242 case 6: | |
| 243 /* exp(finite) overflow */ | |
| 244 exc.type = OVERFLOW; | |
| 245 exc.name = "exp"; | |
| 246 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 247 exc.retval = HUGE; | |
| 248 else | |
| 249 exc.retval = HUGE_VAL; | |
| 250 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 251 errno = ERANGE; | |
| 252 else if (!matherr(&exc)) { | |
| 253 errno = ERANGE; | |
| 254 } | |
| 255 break; | |
| 256 case 7: | |
| 257 /* exp(finite) underflow */ | |
| 258 exc.type = UNDERFLOW; | |
| 259 exc.name = "exp"; | |
| 260 exc.retval = zero; | |
| 261 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 262 errno = ERANGE; | |
| 263 else if (!matherr(&exc)) { | |
| 264 errno = ERANGE; | |
| 265 } | |
| 266 break; | |
| 267 case 8: | |
| 268 /* y0(0) = -inf */ | |
| 269 exc.type = DOMAIN; /* should be SING for IEEE */ | |
| 270 exc.name = "y0"; | |
| 271 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 272 exc.retval = -HUGE; | |
| 273 else | |
| 274 exc.retval = -HUGE_VAL; | |
| 275 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 276 errno = EDOM; | |
| 277 else if (!matherr(&exc)) { | |
| 278 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 279 (void) WRITE2("y0: DOMAIN error\n", 17); | |
| 280 } | |
| 281 errno = EDOM; | |
| 282 } | |
| 283 break; | |
| 284 case 9: | |
| 285 /* y0(x<0) = NaN */ | |
| 286 exc.type = DOMAIN; | |
| 287 exc.name = "y0"; | |
| 288 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 289 exc.retval = -HUGE; | |
| 290 else | |
| 291 exc.retval = -HUGE_VAL; | |
| 292 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 293 errno = EDOM; | |
| 294 else if (!matherr(&exc)) { | |
| 295 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 296 (void) WRITE2("y0: DOMAIN error\n", 17); | |
| 297 } | |
| 298 errno = EDOM; | |
| 299 } | |
| 300 break; | |
| 301 case 10: | |
| 302 /* y1(0) = -inf */ | |
| 303 exc.type = DOMAIN; /* should be SING for IEEE */ | |
| 304 exc.name = "y1"; | |
| 305 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 306 exc.retval = -HUGE; | |
| 307 else | |
| 308 exc.retval = -HUGE_VAL; | |
| 309 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 310 errno = EDOM; | |
| 311 else if (!matherr(&exc)) { | |
| 312 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 313 (void) WRITE2("y1: DOMAIN error\n", 17); | |
| 314 } | |
| 315 errno = EDOM; | |
| 316 } | |
| 317 break; | |
| 318 case 11: | |
| 319 /* y1(x<0) = NaN */ | |
| 320 exc.type = DOMAIN; | |
| 321 exc.name = "y1"; | |
| 322 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 323 exc.retval = -HUGE; | |
| 324 else | |
| 325 exc.retval = -HUGE_VAL; | |
| 326 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 327 errno = EDOM; | |
| 328 else if (!matherr(&exc)) { | |
| 329 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 330 (void) WRITE2("y1: DOMAIN error\n", 17); | |
| 331 } | |
| 332 errno = EDOM; | |
| 333 } | |
| 334 break; | |
| 335 case 12: | |
| 336 /* yn(n,0) = -inf */ | |
| 337 exc.type = DOMAIN; /* should be SING for IEEE */ | |
| 338 exc.name = "yn"; | |
| 339 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 340 exc.retval = -HUGE; | |
| 341 else | |
| 342 exc.retval = -HUGE_VAL; | |
| 343 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 344 errno = EDOM; | |
| 345 else if (!matherr(&exc)) { | |
| 346 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 347 (void) WRITE2("yn: DOMAIN error\n", 17); | |
| 348 } | |
| 349 errno = EDOM; | |
| 350 } | |
| 351 break; | |
| 352 case 13: | |
| 353 /* yn(x<0) = NaN */ | |
| 354 exc.type = DOMAIN; | |
| 355 exc.name = "yn"; | |
| 356 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 357 exc.retval = -HUGE; | |
| 358 else | |
| 359 exc.retval = -HUGE_VAL; | |
| 360 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 361 errno = EDOM; | |
| 362 else if (!matherr(&exc)) { | |
| 363 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 364 (void) WRITE2("yn: DOMAIN error\n", 17); | |
| 365 } | |
| 366 errno = EDOM; | |
| 367 } | |
| 368 break; | |
| 369 case 14: | |
| 370 /* lgamma(finite) overflow */ | |
| 371 exc.type = OVERFLOW; | |
| 372 exc.name = "lgamma"; | |
| 373 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 374 exc.retval = HUGE; | |
| 375 else | |
| 376 exc.retval = HUGE_VAL; | |
| 377 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 378 errno = ERANGE; | |
| 379 else if (!matherr(&exc)) { | |
| 380 errno = ERANGE; | |
| 381 } | |
| 382 break; | |
| 383 case 15: | |
| 384 /* lgamma(-integer) or lgamma(0) */ | |
| 385 exc.type = SING; | |
| 386 exc.name = "lgamma"; | |
| 387 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 388 exc.retval = HUGE; | |
| 389 else | |
| 390 exc.retval = HUGE_VAL; | |
| 391 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 392 errno = EDOM; | |
| 393 else if (!matherr(&exc)) { | |
| 394 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 395 (void) WRITE2("lgamma: SING error\n", 19); | |
| 396 } | |
| 397 errno = EDOM; | |
| 398 } | |
| 399 break; | |
| 400 case 16: | |
| 401 /* log(0) */ | |
| 402 exc.type = SING; | |
| 403 exc.name = "log"; | |
| 404 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 405 exc.retval = -HUGE; | |
| 406 else | |
| 407 exc.retval = -HUGE_VAL; | |
| 408 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 409 errno = ERANGE; | |
| 410 else if (!matherr(&exc)) { | |
| 411 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 412 (void) WRITE2("log: SING error\n", 16); | |
| 413 } | |
| 414 errno = EDOM; | |
| 415 } | |
| 416 break; | |
| 417 case 17: | |
| 418 /* log(x<0) */ | |
| 419 exc.type = DOMAIN; | |
| 420 exc.name = "log"; | |
| 421 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 422 exc.retval = -HUGE; | |
| 423 else | |
| 424 exc.retval = -HUGE_VAL; | |
| 425 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 426 errno = EDOM; | |
| 427 else if (!matherr(&exc)) { | |
| 428 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 429 (void) WRITE2("log: DOMAIN error\n", 18); | |
| 430 } | |
| 431 errno = EDOM; | |
| 432 } | |
| 433 break; | |
| 434 case 18: | |
| 435 /* log10(0) */ | |
| 436 exc.type = SING; | |
| 437 exc.name = "log10"; | |
| 438 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 439 exc.retval = -HUGE; | |
| 440 else | |
| 441 exc.retval = -HUGE_VAL; | |
| 442 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 443 errno = ERANGE; | |
| 444 else if (!matherr(&exc)) { | |
| 445 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 446 (void) WRITE2("log10: SING error\n", 18); | |
| 447 } | |
| 448 errno = EDOM; | |
| 449 } | |
| 450 break; | |
| 451 case 19: | |
| 452 /* log10(x<0) */ | |
| 453 exc.type = DOMAIN; | |
| 454 exc.name = "log10"; | |
| 455 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 456 exc.retval = -HUGE; | |
| 457 else | |
| 458 exc.retval = -HUGE_VAL; | |
| 459 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 460 errno = EDOM; | |
| 461 else if (!matherr(&exc)) { | |
| 462 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 463 (void) WRITE2("log10: DOMAIN error\n", 20); | |
| 464 } | |
| 465 errno = EDOM; | |
| 466 } | |
| 467 break; | |
| 468 case 20: | |
| 469 /* pow(0.0,0.0) */ | |
| 470 /* error only if cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID */ | |
| 471 exc.type = DOMAIN; | |
| 472 exc.name = "pow"; | |
| 473 exc.retval = zero; | |
| 474 if (cyg_libm_get_compat_mode() != CYGNUM_LIBM_COMPAT_SVID) exc.retval = 1.0; | |
| 475 else if (!matherr(&exc)) { | |
| 476 (void) WRITE2("pow(0,0): DOMAIN error\n", 23); | |
| 477 errno = EDOM; | |
| 478 } | |
| 479 break; | |
| 480 case 21: | |
| 481 /* pow(x,y) overflow */ | |
| 482 exc.type = OVERFLOW; | |
| 483 exc.name = "pow"; | |
| 484 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 485 exc.retval = HUGE; | |
| 486 y *= 0.5; | |
| 487 if(x<zero&&rint(y)!=y) exc.retval = -HUGE; | |
| 488 } else { | |
| 489 exc.retval = HUGE_VAL; | |
| 490 y *= 0.5; | |
| 491 if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL; | |
| 492 } | |
| 493 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 494 errno = ERANGE; | |
| 495 else if (!matherr(&exc)) { | |
| 496 errno = ERANGE; | |
| 497 } | |
| 498 break; | |
| 499 case 22: | |
| 500 /* pow(x,y) underflow */ | |
| 501 exc.type = UNDERFLOW; | |
| 502 exc.name = "pow"; | |
| 503 exc.retval = zero; | |
| 504 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 505 errno = ERANGE; | |
| 506 else if (!matherr(&exc)) { | |
| 507 errno = ERANGE; | |
| 508 } | |
| 509 break; | |
| 510 case 23: | |
| 511 /* 0**neg */ | |
| 512 exc.type = DOMAIN; | |
| 513 exc.name = "pow"; | |
| 514 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 515 exc.retval = zero; | |
| 516 else | |
| 517 exc.retval = -HUGE_VAL; | |
| 518 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 519 errno = EDOM; | |
| 520 else if (!matherr(&exc)) { | |
| 521 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 522 (void) WRITE2("pow(0,neg): DOMAIN error\n", 25); | |
| 523 } | |
| 524 errno = EDOM; | |
| 525 } | |
| 526 break; | |
| 527 case 24: | |
| 528 /* neg**non-integral */ | |
| 529 exc.type = DOMAIN; | |
| 530 exc.name = "pow"; | |
| 531 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 532 exc.retval = zero; | |
| 533 else | |
| 534 exc.retval = zero/zero; /* X/Open allow NaN */ | |
| 535 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 536 errno = EDOM; | |
| 537 else if (!matherr(&exc)) { | |
| 538 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 539 (void) WRITE2("neg**non-integral: DOMAIN error\n", 32); | |
| 540 } | |
| 541 errno = EDOM; | |
| 542 } | |
| 543 break; | |
| 544 case 25: | |
| 545 /* sinh(finite) overflow */ | |
| 546 exc.type = OVERFLOW; | |
| 547 exc.name = "sinh"; | |
| 548 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 549 exc.retval = ( (x>zero) ? HUGE : -HUGE); | |
| 550 else | |
| 551 exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL); | |
| 552 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 553 errno = ERANGE; | |
| 554 else if (!matherr(&exc)) { | |
| 555 errno = ERANGE; | |
| 556 } | |
| 557 break; | |
| 558 case 26: | |
| 559 /* sqrt(x<0) */ | |
| 560 exc.type = DOMAIN; | |
| 561 exc.name = "sqrt"; | |
| 562 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 563 exc.retval = zero; | |
| 564 else | |
| 565 exc.retval = zero/zero; | |
| 566 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 567 errno = EDOM; | |
| 568 else if (!matherr(&exc)) { | |
| 569 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 570 (void) WRITE2("sqrt: DOMAIN error\n", 19); | |
| 571 } | |
| 572 errno = EDOM; | |
| 573 } | |
| 574 break; | |
| 575 case 27: | |
| 576 /* fmod(x,0) */ | |
| 577 exc.type = DOMAIN; | |
| 578 exc.name = "fmod"; | |
| 579 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 580 exc.retval = x; | |
| 581 else | |
| 582 exc.retval = zero/zero; | |
| 583 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 584 errno = EDOM; | |
| 585 else if (!matherr(&exc)) { | |
| 586 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 587 (void) WRITE2("fmod: DOMAIN error\n", 20); | |
| 588 } | |
| 589 errno = EDOM; | |
| 590 } | |
| 591 break; | |
| 592 case 28: | |
| 593 /* remainder(x,0) */ | |
| 594 exc.type = DOMAIN; | |
| 595 exc.name = "remainder"; | |
| 596 exc.retval = zero/zero; | |
| 597 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 598 errno = EDOM; | |
| 599 else if (!matherr(&exc)) { | |
| 600 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 601 (void) WRITE2("remainder: DOMAIN error\n", 24); | |
| 602 } | |
| 603 errno = EDOM; | |
| 604 } | |
| 605 break; | |
| 606 case 29: | |
| 607 /* acosh(x<1) */ | |
| 608 exc.type = DOMAIN; | |
| 609 exc.name = "acosh"; | |
| 610 exc.retval = zero/zero; | |
| 611 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 612 errno = EDOM; | |
| 613 else if (!matherr(&exc)) { | |
| 614 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 615 (void) WRITE2("acosh: DOMAIN error\n", 20); | |
| 616 } | |
| 617 errno = EDOM; | |
| 618 } | |
| 619 break; | |
| 620 case 30: | |
| 621 /* atanh(|x|>1) */ | |
| 622 exc.type = DOMAIN; | |
| 623 exc.name = "atanh"; | |
| 624 exc.retval = zero/zero; | |
| 625 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 626 errno = EDOM; | |
| 627 else if (!matherr(&exc)) { | |
| 628 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 629 (void) WRITE2("atanh: DOMAIN error\n", 20); | |
| 630 } | |
| 631 errno = EDOM; | |
| 632 } | |
| 633 break; | |
| 634 case 31: | |
| 635 /* atanh(|x|=1) */ | |
| 636 exc.type = SING; | |
| 637 exc.name = "atanh"; | |
| 638 exc.retval = x/zero; /* sign(x)*inf */ | |
| 639 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 640 errno = EDOM; | |
| 641 else if (!matherr(&exc)) { | |
| 642 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 643 (void) WRITE2("atanh: SING error\n", 18); | |
| 644 } | |
| 645 errno = EDOM; | |
| 646 } | |
| 647 break; | |
| 648 case 32: | |
| 649 /* scalb overflow; SVID also returns +-HUGE_VAL */ | |
| 650 exc.type = OVERFLOW; | |
| 651 exc.name = "scalb"; | |
| 652 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL; | |
| 653 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 654 errno = ERANGE; | |
| 655 else if (!matherr(&exc)) { | |
| 656 errno = ERANGE; | |
| 657 } | |
| 658 break; | |
| 659 case 33: | |
| 660 /* scalb underflow */ | |
| 661 exc.type = UNDERFLOW; | |
| 662 exc.name = "scalb"; | |
| 663 exc.retval = copysign(zero,x); | |
| 664 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 665 errno = ERANGE; | |
| 666 else if (!matherr(&exc)) { | |
| 667 errno = ERANGE; | |
| 668 } | |
| 669 break; | |
| 670 case 34: | |
| 671 /* j0(|x|>X_TLOSS) */ | |
| 672 exc.type = TLOSS; | |
| 673 exc.name = "j0"; | |
| 674 exc.retval = zero; | |
| 675 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 676 errno = ERANGE; | |
| 677 else if (!matherr(&exc)) { | |
| 678 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 679 (void) WRITE2(exc.name, 2); | |
| 680 (void) WRITE2(": TLOSS error\n", 14); | |
| 681 } | |
| 682 errno = ERANGE; | |
| 683 } | |
| 684 break; | |
| 685 case 35: | |
| 686 /* y0(x>X_TLOSS) */ | |
| 687 exc.type = TLOSS; | |
| 688 exc.name = "y0"; | |
| 689 exc.retval = zero; | |
| 690 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 691 errno = ERANGE; | |
| 692 else if (!matherr(&exc)) { | |
| 693 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 694 (void) WRITE2(exc.name, 2); | |
| 695 (void) WRITE2(": TLOSS error\n", 14); | |
| 696 } | |
| 697 errno = ERANGE; | |
| 698 } | |
| 699 break; | |
| 700 case 36: | |
| 701 /* j1(|x|>X_TLOSS) */ | |
| 702 exc.type = TLOSS; | |
| 703 exc.name = "j1"; | |
| 704 exc.retval = zero; | |
| 705 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 706 errno = ERANGE; | |
| 707 else if (!matherr(&exc)) { | |
| 708 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 709 (void) WRITE2(exc.name, 2); | |
| 710 (void) WRITE2(": TLOSS error\n", 14); | |
| 711 } | |
| 712 errno = ERANGE; | |
| 713 } | |
| 714 break; | |
| 715 case 37: | |
| 716 /* y1(x>X_TLOSS) */ | |
| 717 exc.type = TLOSS; | |
| 718 exc.name = "y1"; | |
| 719 exc.retval = zero; | |
| 720 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 721 errno = ERANGE; | |
| 722 else if (!matherr(&exc)) { | |
| 723 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 724 (void) WRITE2(exc.name, 2); | |
| 725 (void) WRITE2(": TLOSS error\n", 14); | |
| 726 } | |
| 727 errno = ERANGE; | |
| 728 } | |
| 729 break; | |
| 730 case 38: | |
| 731 /* jn(|x|>X_TLOSS) */ | |
| 732 exc.type = TLOSS; | |
| 733 exc.name = "jn"; | |
| 734 exc.retval = zero; | |
| 735 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 736 errno = ERANGE; | |
| 737 else if (!matherr(&exc)) { | |
| 738 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 739 (void) WRITE2(exc.name, 2); | |
| 740 (void) WRITE2(": TLOSS error\n", 14); | |
| 741 } | |
| 742 errno = ERANGE; | |
| 743 } | |
| 744 break; | |
| 745 case 39: | |
| 746 /* yn(x>X_TLOSS) */ | |
| 747 exc.type = TLOSS; | |
| 748 exc.name = "yn"; | |
| 749 exc.retval = zero; | |
| 750 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 751 errno = ERANGE; | |
| 752 else if (!matherr(&exc)) { | |
| 753 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 754 (void) WRITE2(exc.name, 2); | |
| 755 (void) WRITE2(": TLOSS error\n", 14); | |
| 756 } | |
| 757 errno = ERANGE; | |
| 758 } | |
| 759 break; | |
| 760 case 40: | |
| 761 /* gamma(finite) overflow */ | |
| 762 exc.type = OVERFLOW; | |
| 763 exc.name = "gamma"; | |
| 764 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 765 exc.retval = HUGE; | |
| 766 else | |
| 767 exc.retval = HUGE_VAL; | |
| 768 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 769 errno = ERANGE; | |
| 770 else if (!matherr(&exc)) { | |
| 771 errno = ERANGE; | |
| 772 } | |
| 773 break; | |
| 774 case 41: | |
| 775 /* gamma(-integer) or gamma(0) */ | |
| 776 exc.type = SING; | |
| 777 exc.name = "gamma"; | |
| 778 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) | |
| 779 exc.retval = HUGE; | |
| 780 else | |
| 781 exc.retval = HUGE_VAL; | |
| 782 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 783 errno = EDOM; | |
| 784 else if (!matherr(&exc)) { | |
| 785 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID) { | |
| 786 (void) WRITE2("gamma: SING error\n", 18); | |
| 787 } | |
| 788 errno = EDOM; | |
| 789 } | |
| 790 break; | |
| 791 case 42: | |
| 792 /* pow(NaN,0.0) */ | |
| 793 /* error only if cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_SVID & CYGNUM_LIBM_COMPAT_XOPEN */ | |
| 794 exc.type = DOMAIN; | |
| 795 exc.name = "pow"; | |
| 796 exc.retval = x; | |
| 797 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_IEEE || | |
| 798 cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) exc.retval = 1.0; | |
| 799 else if (!matherr(&exc)) { | |
| 800 errno = EDOM; | |
| 801 } | |
| 802 break; | |
| 803 case 43: | |
| 804 /* ldexp overflow; SVID also returns +-HUGE_VAL */ | |
| 805 exc.type = OVERFLOW; | |
| 806 exc.name = "ldexp"; | |
| 807 exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL; | |
| 808 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 809 errno = ERANGE; | |
| 810 else if (!matherr(&exc)) { | |
| 811 errno = ERANGE; | |
| 812 } | |
| 813 break; | |
| 814 case 44: | |
| 815 /* ldexp underflow */ | |
| 816 exc.type = UNDERFLOW; | |
| 817 exc.name = "ldexp"; | |
| 818 exc.retval = copysign(zero,x); | |
| 819 if (cyg_libm_get_compat_mode() == CYGNUM_LIBM_COMPAT_POSIX) | |
| 820 errno = ERANGE; | |
| 821 else if (!matherr(&exc)) { | |
| 822 errno = ERANGE; | |
| 823 } | |
| 824 break; | |
| 825 } | |
| 826 return exc.retval; | |
| 827 } | |
| 828 | |
| 829 #endif // ifdef CYGPKG_LIBM | |
| 830 | |
| 831 // EOF standard.c |
