From 1bb874fdbd2f71777fc86d29645cd0a8dbab85f8 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 17 Jun 2007 17:46:01 +0000 Subject: [PATCH] Add nan, nanf, nanl. Dragonfly-bug: http://bugs.dragonflybsd.org/issue632 Obtained-from: NetBSD --- include/math.h | 5 ++- lib/libm/Makefile | 3 +- lib/libm/gen/Makefile.inc | 9 +++++ lib/libm/gen/nan.3 | 101 ++++++++++++++++++++++++++++++++++++++++++++++ lib/libm/gen/nan.c | 88 ++++++++++++++++++++++++++++++++++++++++ lib/libm/gen/nanf.c | 44 ++++++++++++++++++++ lib/libm/gen/nanl.c | 44 ++++++++++++++++++++ lib/libm/man/math.3 | 3 +- 8 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 lib/libm/gen/Makefile.inc create mode 100644 lib/libm/gen/nan.3 create mode 100644 lib/libm/gen/nan.c create mode 100644 lib/libm/gen/nanf.c create mode 100644 lib/libm/gen/nanl.c diff --git a/include/math.h b/include/math.h index c8fe368fb3..80d259c0de 100644 --- a/include/math.h +++ b/include/math.h @@ -9,7 +9,7 @@ * ==================================================== * * $NetBSD: math.h,v 1.41 2005/07/21 12:56:29 christos Exp $ - * $DragonFly: src/include/math.h,v 1.10 2007/06/17 06:26:18 pavalos Exp $ + * $DragonFly: src/include/math.h,v 1.11 2007/06/17 17:46:01 pavalos Exp $ */ /* @@ -314,6 +314,9 @@ float remainderf(float, float); /* 7.2.11 manipulation */ float copysignf(float, float); +double nan(const char *); +float nanf(const char *); +long double nanl(const char *); float nextafterf(float, float); #endif /* __ISO_C_VISIBLE >= 1999 */ diff --git a/lib/libm/Makefile b/lib/libm/Makefile index 8433edf599..2124be84f3 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -1,4 +1,4 @@ -# $DragonFly: src/lib/libm/Makefile,v 1.6 2005/10/01 14:40:33 corecode Exp $ +# $DragonFly: src/lib/libm/Makefile,v 1.7 2007/06/17 17:46:01 pavalos Exp $ LIB= m SHLIB_MAJOR= 3 @@ -13,6 +13,7 @@ ARCHDIR= i386 .if exists(arch/${ARCHDIR}/Makefile.inc) .include "arch/${ARCHDIR}/Makefile.inc" .endif +.include "gen/Makefile.inc" .include "man/Makefile.inc" .include "src/Makefile.inc" diff --git a/lib/libm/gen/Makefile.inc b/lib/libm/gen/Makefile.inc new file mode 100644 index 0000000000..0c63c22ca5 --- /dev/null +++ b/lib/libm/gen/Makefile.inc @@ -0,0 +1,9 @@ +# $DragonFly: src/lib/libm/gen/Makefile.inc,v 1.1 2007/06/17 17:46:01 pavalos Exp $ + +.PATH: ${.CURDIR}/gen + +SRCS+= nan.c nanf.c nanl.c + +MAN+= nan.3 + +MLINKS+=nan.3 nanf.3 nan.3 nanl.3 diff --git a/lib/libm/gen/nan.3 b/lib/libm/gen/nan.3 new file mode 100644 index 0000000000..9d979017d7 --- /dev/null +++ b/lib/libm/gen/nan.3 @@ -0,0 +1,101 @@ +.\" +.\" Copyright (c) 2006 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Klaus Klein. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.\" $NetBSD: nan.3,v 1.1 2006/03/15 22:07:09 kleink Exp $ +.\" $DragonFly: src/lib/libm/gen/nan.3,v 1.1 2007/06/17 17:46:01 pavalos Exp $ +.\" +.Dd March 15, 2006 +.Dt NAN 3 +.Os +.Sh NAME +.Nm nan , +.Nm nanf , +.Nm nanl +.Nd return quiet NaN +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn nan "const char *tagp" +.Ft float +.Fn nanf "const char *tagp" +.Ft long double +.Fn nanl "const char *tagp" +.Sh DESCRIPTION +The call +.Fn nan "\*qn-char-sequence\*q" +is equivalent to the call +.Fn strtod "\*qNAN(n-char-sequence)\*q" "NULL" . +The call +.Fn nan "\*q\*q" +is equivalent to the call +.Fn strtod "\*qNAN()\*q" "NULL" . +.Pp +The +.Fn nanf +and +.Fn nanl +functions are equivalent to +.Fn nan +but substituting +.Fn strtod . +.Sh RETURN VALUES +.Ss IEEE 754 +The +.Fn nan , +.Fn nanf , +and +.Fn nanl +functions return a quiet NaN as specified by +.Fa tagp . +.Ss VAX +The +.Fn nan , +.Fn nanf , +and +.Fn nanl +functions return zero. +.Sh SEE ALSO +.Xr math 3 , +.Xr strtod 3 +.Sh STANDARDS +The +.Fn nan , +.Fn nanf , +and +.Fn nanl +functions conform to +.St -isoC-99 . diff --git a/lib/libm/gen/nan.c b/lib/libm/gen/nan.c new file mode 100644 index 0000000000..c4e05d4594 --- /dev/null +++ b/lib/libm/gen/nan.c @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: nan.c,v 1.1 2006/03/15 22:07:09 kleink Exp $ + * $DragonFly: src/lib/libm/gen/nan.c,v 1.1 2007/06/17 17:46:01 pavalos Exp $ + */ + +#include +#include +#include +#include +#include + + +#ifndef NAN_FUNCTION +#define NAN_FUNCTION nan +#define NAN_TYPE double +#define NAN_STRTOD strtod +#endif + +NAN_TYPE +NAN_FUNCTION(const char *tagp) +{ + const char *nstr; + char *buf; + NAN_TYPE res; + + _DIAGASSERT(tagp != NULL); + + nstr = "NAN()"; + buf = NULL; + + if (tagp[0] != '\0') { + size_t l; + + l = strlen(tagp); + buf = malloc(5 + l + 1); + + if (buf != NULL) { + /* Avoiding stdio in libm. */ + memcpy(buf, "NAN(", 4); + memcpy(buf + 4, tagp, l); + memcpy(buf + 4 + l, ")", 2); + nstr = buf; + } else { + /* Best effort: Fall back to "NAN()". */ + } + } + + res = NAN_STRTOD(nstr, NULL); + + if (buf != NULL) + free(buf); + + return res; +} diff --git a/lib/libm/gen/nanf.c b/lib/libm/gen/nanf.c new file mode 100644 index 0000000000..6e682e475d --- /dev/null +++ b/lib/libm/gen/nanf.c @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: nanf.c,v 1.1 2006/03/15 22:07:09 kleink Exp $ + * $DragonFly: src/lib/libm/gen/nanf.c,v 1.1 2007/06/17 17:46:01 pavalos Exp $ + */ + +#define NAN_FUNCTION nanf +#define NAN_TYPE float +#define NAN_STRTOD strtod /* XXX should be strtof */ + +#include "nan.c" diff --git a/lib/libm/gen/nanl.c b/lib/libm/gen/nanl.c new file mode 100644 index 0000000000..614c213556 --- /dev/null +++ b/lib/libm/gen/nanl.c @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: nanl.c,v 1.1 2006/03/15 22:07:09 kleink Exp $ + * $DragonFly: src/lib/libm/gen/nanl.c,v 1.1 2007/06/17 17:46:01 pavalos Exp $ + */ + +#define NAN_FUNCTION nanl +#define NAN_TYPE long double +#define NAN_STRTOD strtod /* XXX should be strtold */ + +#include "nan.c" diff --git a/lib/libm/man/math.3 b/lib/libm/man/math.3 index 70a892cb32..4b41819162 100644 --- a/lib/libm/man/math.3 +++ b/lib/libm/man/math.3 @@ -27,7 +27,7 @@ .\" .\" from: @(#)math.3 6.10 (Berkeley) 5/6/91 .\" $NetBSD: math.3,v 1.18 2003/12/03 23:31:21 jschauma Exp $ -.\" $DragonFly: src/lib/libm/man/math.3,v 1.2 2007/06/17 06:26:18 pavalos Exp $ +.\" $DragonFly: src/lib/libm/man/math.3,v 1.3 2007/06/17 17:46:01 pavalos Exp $ .\" .TH MATH 3 "Dec 3, 2003" .UC 4 @@ -87,6 +87,7 @@ lgamma lgamma.3 log gamma function ??? log exp.3 natural logarithm 1 log10 exp.3 logarithm to base 10 3 log1p exp.3 log(1+x) 1 +nan nan.3 return quiet \*(nn 0 nextafter ieee.3 next representable number 0 pow exp.3 exponential x**y 60\-500 remainder ieee.3 remainder 0 -- 2.11.4.GIT