blob: eee3b1cc48269bf9ac978d6fa8e70ac15977a15c [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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
25double 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}
34libm_hidden_def(nan)
35
36libm_hidden_proto(nanf)
37float 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}
46libm_hidden_def(nanf)
47
48#if defined __UCLIBC_HAS_LONG_DOUBLE_MATH__ && !defined __NO_LONG_DOUBLE_MATH
49libm_hidden_proto(nanl)
50long 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}
59libm_hidden_def(nanl)
60#endif