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