lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org> |
| 4 | * |
| 5 | * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. |
| 6 | */ |
| 7 | |
| 8 | /*********************************************************************** |
| 9 | nan, nanf, nanl - return quiet NaN |
| 10 | |
| 11 | These functions shall return a quiet NaN, if available, with content |
| 12 | indicated through tagp. |
| 13 | |
| 14 | If the implementation does not support quiet NaNs, these functions |
| 15 | shall return zero. |
| 16 | |
| 17 | Calls: strlen(), sprintf(), strtod() |
| 18 | |
| 19 | ***********************************************************************/ |
| 20 | #include <math.h> |
| 21 | #include <string.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | double nan (const char *tagp) |
| 26 | { |
| 27 | if (tagp[0] != '\0') { |
| 28 | char buf[6 + strlen (tagp)]; |
| 29 | sprintf (buf, "NAN(%s)", tagp); |
| 30 | return strtod (buf, NULL); |
| 31 | } |
| 32 | return NAN; |
| 33 | } |
| 34 | libm_hidden_def(nan) |
| 35 | |
| 36 | libm_hidden_proto(nanf) |
| 37 | float nanf (const char *tagp) |
| 38 | { |
| 39 | if (tagp[0] != '\0') { |
| 40 | char buf[6 + strlen (tagp)]; |
| 41 | sprintf (buf, "NAN(%s)", tagp); |
| 42 | return strtof (buf, NULL); |
| 43 | } |
| 44 | return NAN; |
| 45 | } |
| 46 | libm_hidden_def(nanf) |
| 47 | |
| 48 | #if defined __UCLIBC_HAS_LONG_DOUBLE_MATH__ && !defined __NO_LONG_DOUBLE_MATH |
| 49 | libm_hidden_proto(nanl) |
| 50 | long double nanl (const char *tagp) |
| 51 | { |
| 52 | if (tagp[0] != '\0') { |
| 53 | char buf[6 + strlen (tagp)]; |
| 54 | sprintf (buf, "NAN(%s)", tagp); |
| 55 | return strtold (buf, NULL); |
| 56 | } |
| 57 | return NAN; |
| 58 | } |
| 59 | libm_hidden_def(nanl) |
| 60 | #endif |