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