summaryrefslogtreecommitdiff
path: root/libm/nan.c
blob: 16e5c1772473bbf5322b66f5dcef5fe869ecf598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* vi: set sw=4 ts=4: */
/*
 * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org>
 *
 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 */

/***********************************************************************
    nan, nanf, nanl - return quiet NaN

	These functions shall return a quiet NaN, if available, with content
	indicated through tagp.

	If the implementation does not support quiet NaNs, these functions
	shall return zero.

   Calls:  strlen(), sprintf(), strtod()

***********************************************************************/
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

double nan (const char *tagp)
{
	if (tagp[0] != '\0') {
		char buf[6 + strlen (tagp)];
		sprintf (buf, "NAN(%s)", tagp);
		return strtod (buf, NULL);
	}
	return NAN;
}

float nanf (const char *tagp)
{
	if (tagp[0] != '\0') {
		char buf[6 + strlen (tagp)];
		sprintf (buf, "NAN(%s)", tagp);
		return strtof (buf, NULL);
	}
	return NAN;
}

#if 0
long double nanl (const char *tagp)
{
	if (tagp[0] != '\0') {
		char buf[6 + strlen (tagp)];
		sprintf (buf, "NAN(%s)", tagp);
		return strtold (buf, NULL);
	}
	return NAN;
}
#endif