Module Name: src Committed By: christos Date: Sun Oct 4 22:04:30 UTC 2009
Modified Files: src/lib/libm: Makefile shlib_version Added Files: src/lib/libm/man: fdim.3 fmax.3 src/lib/libm/src: s_fdim.c s_fmax.c s_fmaxf.c s_fmaxl.c s_fmin.c s_fminf.c s_fminl.c Log Message: add f{min,max,dim}{,l,f} from FreeBSD To generate a diff of this commit: cvs rdiff -u -r1.89 -r1.90 src/lib/libm/Makefile cvs rdiff -u -r1.9 -r1.10 src/lib/libm/shlib_version cvs rdiff -u -r0 -r1.1 src/lib/libm/man/fdim.3 src/lib/libm/man/fmax.3 cvs rdiff -u -r0 -r1.1 src/lib/libm/src/s_fdim.c src/lib/libm/src/s_fmax.c \ src/lib/libm/src/s_fmaxf.c src/lib/libm/src/s_fmaxl.c \ src/lib/libm/src/s_fmin.c src/lib/libm/src/s_fminf.c \ src/lib/libm/src/s_fminl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libm/Makefile diff -u src/lib/libm/Makefile:1.89 src/lib/libm/Makefile:1.90 --- src/lib/libm/Makefile:1.89 Sun Jan 18 15:42:11 2009 +++ src/lib/libm/Makefile Sun Oct 4 18:04:30 2009 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.89 2009/01/18 20:42:11 he Exp $ +# $NetBSD: Makefile,v 1.90 2009/10/04 22:04:30 christos Exp $ # # @(#)Makefile 5.1beta 93/09/24 # @@ -136,7 +136,9 @@ w_pow.c w_powf.c w_remainder.c w_remainderf.c w_scalb.c w_scalbf.c \ w_sinh.c w_sinhf.c w_sqrt.c w_sqrtf.c \ lrint.c lrintf.c llrint.c llrintf.c lround.c lroundf.c llround.c \ - llroundf.c + llroundf.c \ + s_fmax.c s_fmaxf.c s_fmaxl.c s_fmin.c s_fminf.c s_fminl.c s_fdim.c + # Also in libc. #COMMON_SRCS += s_frexp.c s_ldexp.c s_modf.c @@ -186,7 +188,7 @@ cos.3 cosh.3 erf.3 exp.3 fabs.3 floor.3 fmod.3 frexp.3 hypot.3 ieee.3 \ ieee_test.3 isinff.3 j0.3 ldexp.3 lgamma.3 lrint.3 \ math.3 modf.3 rint.3 round.3 sin.3 sinh.3 \ - sqrt.3 tan.3 tanh.3 trunc.3 + sqrt.3 tan.3 tanh.3 trunc.3 fmax.3 fdim.3 MLINKS+=acos.3 acosf.3 MLINKS+=acosh.3 acoshf.3 @@ -227,6 +229,13 @@ MLINKS+=tanh.3 tanhf.3 MLINKS+=round.3 roundf.3 MLINKS+=trunc.3 truncf.3 +MLINKS+=fmax.3 fmaxl.3 +MLINKS+=fmax.3 fmaxf.3 +MLINKS+=fmax.3 fmin.3 +MLINKS+=fmax.3 fminl.3 +MLINKS+=fmax.3 fminf.3 +MLINKS+=fdim.3 fdiml.3 +MLINKS+=fdim.3 fdimf.3 .if (${MKCOMPLEX} != "no") .include "${.CURDIR}/complex/Makefile.inc" Index: src/lib/libm/shlib_version diff -u src/lib/libm/shlib_version:1.9 src/lib/libm/shlib_version:1.10 --- src/lib/libm/shlib_version:1.9 Mon Aug 20 12:01:30 2007 +++ src/lib/libm/shlib_version Sun Oct 4 18:04:30 2009 @@ -1,5 +1,5 @@ -# $NetBSD: shlib_version,v 1.9 2007/08/20 16:01:30 drochner Exp $ +# $NetBSD: shlib_version,v 1.10 2009/10/04 22:04:30 christos Exp $ # Remember to update distrib/sets/lists/base/shl.* when changing # major=0 -minor=6 +minor=7 Added files: Index: src/lib/libm/man/fdim.3 diff -u /dev/null src/lib/libm/man/fdim.3:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/man/fdim.3 Sun Oct 4 18:04:30 2009 @@ -0,0 +1,87 @@ +.\" Copyright (c) 2004 David Schultz <d...@freebsd.org> +.\" All rights reserved. +.\" +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD: src/lib/msun/man/fdim.3,v 1.1 2004/06/30 07:04:01 das Exp $ +.\" $NetBSD: fdim.3,v 1.1 2009/10/04 22:04:30 christos Exp $ +.\" +.Dd June 29, 2004 +.Dt FDIM 3 +.Os +.Sh NAME +.Nm fdim , +.Nm fdimf , +.Nm fdiml +.Nd positive difference functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn fdim "double x" "double y" +.Ft float +.Fn fdimf "float x" "float y" +.Ft long double +.Fn fdiml "long double x" "long double y" +.Sh DESCRIPTION +The +.Fn fdim , +.Fn fdimf , +and +.Fn fdiml +functions return the positive difference between +.Fa x +and +.Fa y . +That is, if +.Fa x\- Ns Fa y +is positive, then +.Fa x\- Ns Fa y +is returned. +If either +.Fa x +or +.Fa y +is an \*(Na, then an \*(Na is returned. +Otherwise, the result is +.Li +0.0 . +.Pp +Overflow or underflow may occur iff the exact result is not +representable in the return type. +No other exceptions are raised. +.Sh SEE ALSO +.Xr fabs 3 , +.Xr fmax 3 , +.Xr fmin 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn fdim , +.Fn fdimf , +and +.Fn fdiml +functions conform to +.St -isoC-99 . +.Sh HISTORY +These routines first appeared in +.Fx 5.3 . Index: src/lib/libm/man/fmax.3 diff -u /dev/null src/lib/libm/man/fmax.3:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/man/fmax.3 Sun Oct 4 18:04:30 2009 @@ -0,0 +1,100 @@ +.\" Copyright (c) 2004 David Schultz <d...@freebsd.org> +.\" All rights reserved. +.\" +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. +.\" +.\" $FreeBSD: src/lib/msun/man/fmax.3,v 1.2 2005/01/14 09:12:05 ru Exp $ +.\" $NetBSD: fmax.3,v 1.1 2009/10/04 22:04:30 christos Exp $ +.\" +.Dd June 29, 2004 +.Dt FMAX 3 +.Os +.Sh NAME +.Nm fmax , +.Nm fmaxf , +.Nm fmaxl , +.Nm fmin , +.Nm fminf , +.Nm fminl +.Nd floating-point maximum and minimum functions +.Sh LIBRARY +.Lb libm +.Sh SYNOPSIS +.In math.h +.Ft double +.Fn fmax "double x" "double y" +.Ft float +.Fn fmaxf "float x" "float y" +.Ft "long double" +.Fn fmaxl "long double x" "long double y" +.Ft double +.Fn fmin "double x" "double y" +.Ft float +.Fn fminf "float x" "float y" +.Ft "long double" +.Fn fminl "long double x" "long double y" +.Sh DESCRIPTION +The +.Fn fmax , +.Fn fmaxf , +and +.Fn fmaxl +functions return the larger of +.Fa x +and +.Fa y , +and likewise, the +.Fn fmin , +.Fn fminf , +and +.Fn fminl +functions return the smaller of +.Fa x +and +.Fa y . +They treat +.Li +0.0 +as being larger than +.Li -0.0 . +If one argument is an \*(Na, then the other argument is returned. +If both arguments are \*(Nas, then the result is an \*(Na. +These routines do not raise any floating-point exceptions. +.Sh SEE ALSO +.Xr fabs 3 , +.Xr fdim 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn fmax , +.Fn fmaxf , +.Fn fmaxl , +.Fn fmin , +.Fn fminf , +and +.Fn fminl +functions conform to +.St -isoC-99 . +.Sh HISTORY +These routines first appeared in +.Fx 5.3 +and +.Nx 6.0 . Index: src/lib/libm/src/s_fdim.c diff -u /dev/null src/lib/libm/src/s_fdim.c:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/src/s_fdim.c Sun Oct 4 18:04:30 2009 @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2004 David Schultz <d...@freebsd.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <sys/cdefs.h> +__RCSID("NetBSD$"); +#ifdef notdef +__FBSDID("$FreeBSD: src/lib/msun/src/s_fdim.c,v 1.1 2004/06/30 07:04:01 das Exp $"); +#endif + +#include <math.h> + +#define DECL(type, fn) \ +type \ +fn(type x, type y) \ +{ \ + \ + if (isnan(x)) \ + return (x); \ + if (isnan(y)) \ + return (y); \ + return (x > y ? x - y : 0.0); \ +} + +DECL(double, fdim) +DECL(float, fdimf) +DECL(long double, fdiml) Index: src/lib/libm/src/s_fmax.c diff -u /dev/null src/lib/libm/src/s_fmax.c:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/src/s_fmax.c Sun Oct 4 18:04:30 2009 @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2004 David Schultz <d...@freebsd.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <sys/cdefs.h> +__RCSID("NetBSD$"); +#ifdef notdef +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmax.c,v 1.1 2004/06/30 07:04:01 das Exp $"); +#endif + +#include <math.h> + +#include <machine/ieee.h> + +double +fmax(double x, double y) +{ + union ieee_double_u u[2]; + + u[0].dblu_d = x; + u[1].dblu_d = y; + + /* Check for NaNs to avoid raising spurious exceptions. */ + if (u[0].dblu_dbl.dbl_exp == DBL_EXP_INFNAN && + (u[0].dblu_dbl.dbl_frach | u[0].dblu_dbl.dbl_fracl) != 0) + return (y); + if (u[1].dblu_dbl.dbl_exp == DBL_EXP_INFNAN && + (u[1].dblu_dbl.dbl_frach | u[1].dblu_dbl.dbl_fracl) != 0) + return (x); + + /* Handle comparisons of signed zeroes. */ + if (u[0].dblu_dbl.dbl_sign != u[1].dblu_dbl.dbl_sign) + return (u[u[0].dblu_dbl.dbl_sign].dblu_d); + + return (x > y ? x : y); +} Index: src/lib/libm/src/s_fmaxf.c diff -u /dev/null src/lib/libm/src/s_fmaxf.c:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/src/s_fmaxf.c Sun Oct 4 18:04:30 2009 @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2004 David Schultz <d...@freebsd.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <sys/cdefs.h> +__RCSID("NetBSD$"); +#ifdef notdef +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmaxf.c,v 1.1 2004/06/30 07:04:01 das Exp $"); +#endif + +#include <math.h> + +#include <machine/ieee.h> + +float +fmaxf(float x, float y) +{ + union ieee_single_u u[2]; + + u[0].sngu_f = x; + u[1].sngu_f = y; + + /* Check for NaNs to avoid raising spurious exceptions. */ + if (u[0].sngu_sng.sng_exp == SNG_EXP_INFNAN && + u[0].sngu_sng.sng_frac != 0) + return (y); + if (u[1].sngu_sng.sng_exp == SNG_EXP_INFNAN && + u[1].sngu_sng.sng_frac != 0) + return (x); + + /* Handle comparisons of sng_signed zeroes. */ + if (u[0].sngu_sng.sng_sign != u[1].sngu_sng.sng_sign) + return (u[u[0].sngu_sng.sng_sign].sngu_f); + + return (x > y ? x : y); +} Index: src/lib/libm/src/s_fmaxl.c diff -u /dev/null src/lib/libm/src/s_fmaxl.c:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/src/s_fmaxl.c Sun Oct 4 18:04:30 2009 @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2004 David Schultz <d...@freebsd.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <sys/cdefs.h> +__RCSID("NetBSD$"); +#ifdef notdef +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmaxl.c,v 1.1 2004/06/30 07:04:01 das Exp $"); +#endif + +#include <math.h> + +#include <machine/ieee.h> +#ifdef EXT_EXP_INFNAN +long double +fmaxl(long double x, long double y) +{ + union ieee_ext_u u[2]; + + u[0].extu_ld = x; + u[0].extu_ext.ext_frach &= ~0x80000000; + u[1].extu_ld = y; + u[1].extu_ext.ext_frach &= ~0x80000000; + + /* Check for NaNs to avoid raising spurious exceptions. */ + if (u[0].extu_ext.ext_exp == EXT_EXP_INFNAN && + (u[0].extu_ext.ext_frach | u[0].extu_ext.ext_fracl) != 0) + return (y); + if (u[1].extu_ext.ext_exp == EXT_EXP_INFNAN && + (u[1].extu_ext.ext_frach | u[1].extu_ext.ext_fracl) != 0) + return (x); + + /* Handle comparisons of ext_signed zeroes. */ + if (u[0].extu_ext.ext_sign != u[1].extu_ext.ext_sign) + return (u[0].extu_ext.ext_sign ? y : x); + + return (x > y ? x : y); +} +#endif Index: src/lib/libm/src/s_fmin.c diff -u /dev/null src/lib/libm/src/s_fmin.c:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/src/s_fmin.c Sun Oct 4 18:04:30 2009 @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2004 David Schultz <d...@freebsd.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: s_fmin.c,v 1.1 2009/10/04 22:04:30 christos Exp $"); +#ifdef notdef +__FBSDID("$FreeBSD: src/lib/msun/src/s_fmin.c,v 1.1 2004/06/30 07:04:01 das Exp $"); +#endif + +#include <math.h> + +#include <machine/ieee.h> + +double +fmin(double x, double y) +{ + union ieee_double_u u[2]; + + u[0].dblu_d = x; + u[1].dblu_d = y; + + /* Check for NaNs to avoid raising spurious exceptions. */ + if (u[0].dblu_dbl.dbl_exp == DBL_EXP_INFNAN && + (u[0].dblu_dbl.dbl_frach | u[0].dblu_dbl.dbl_fracl) != 0) + return (y); + if (u[1].dblu_dbl.dbl_exp == DBL_EXP_INFNAN && + (u[1].dblu_dbl.dbl_frach | u[1].dblu_dbl.dbl_fracl) != 0) + return (x); + + /* Handle comparisons of signed zeroes. */ + if (u[0].dblu_dbl.dbl_sign != u[1].dblu_dbl.dbl_sign) + return (u[u[1].dblu_dbl.dbl_sign].dblu_d); + + return (x < y ? x : y); +} Index: src/lib/libm/src/s_fminf.c diff -u /dev/null src/lib/libm/src/s_fminf.c:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/src/s_fminf.c Sun Oct 4 18:04:30 2009 @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2004 David Schultz <d...@freebsd.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <sys/cdefs.h> +__RCSID("NetBSD$"); +#ifdef notdef +__FBSDID("$FreeBSD: src/lib/msun/src/s_fminf.c,v 1.1 2004/06/30 07:04:01 das Exp $"); +#endif + +#include <math.h> + +#include <machine/ieee.h> + +float +fminf(float x, float y) +{ + union ieee_single_u u[2]; + + u[0].sngu_f = x; + u[1].sngu_f = y; + + /* Check for NaNs to avoid raising spurious exceptions. */ + if (u[0].sngu_sng.sng_exp == SNG_EXP_INFNAN && + u[0].sngu_sng.sng_frac != 0) + return (y); + if (u[1].sngu_sng.sng_exp == SNG_EXP_INFNAN && + u[1].sngu_sng.sng_frac != 0) + return (x); + + /* Handle comparisons of sng_singed zeroes. */ + if (u[0].sngu_sng.sng_sign != u[1].sngu_sng.sng_sign) + return (u[u[1].sngu_sng.sng_sign].sngu_f); + + return (x < y ? x : y); +} Index: src/lib/libm/src/s_fminl.c diff -u /dev/null src/lib/libm/src/s_fminl.c:1.1 --- /dev/null Sun Oct 4 18:04:30 2009 +++ src/lib/libm/src/s_fminl.c Sun Oct 4 18:04:30 2009 @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2004 David Schultz <d...@freebsd.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include <sys/cdefs.h> +__RCSID("NetBSD$"); +#ifdef notdef +__FBSDID("$FreeBSD: src/lib/msun/src/s_fminl.c,v 1.1 2004/06/30 07:04:01 das Exp $"); +#endif + +#include <math.h> + +#include <machine/ieee.h> +#ifdef EXT_EXP_INFNAN +long double +fminl(long double x, long double y) +{ + union ieee_ext_u u[2]; + + u[0].extu_ld = x; + u[0].extu_ext.ext_frach &= ~0x80000000; + u[1].extu_ld = y; + u[1].extu_ext.ext_frach &= ~0x80000000; + + /* Check for NaNs to avoid raising spurious exceptions. */ + if (u[0].extu_ext.ext_exp == EXT_EXP_INFNAN && + (u[0].extu_ext.ext_frach | u[0].extu_ext.ext_fracl) != 0) + return (y); + if (u[1].extu_ext.ext_exp == EXT_EXP_INFNAN && + (u[1].extu_ext.ext_frach | u[1].extu_ext.ext_fracl) != 0) + return (x); + + /* Handle comparisons of ext_signed zeroes. */ + if (u[0].extu_ext.ext_sign != u[1].extu_ext.ext_sign) + return (u[1].extu_ext.ext_sign ? y : x); + + return (x < y ? x : y); +} +#endif