diff options
author | Martynas Venckus <martynas@cvs.openbsd.org> | 2011-04-28 18:05:40 +0000 |
---|---|---|
committer | Martynas Venckus <martynas@cvs.openbsd.org> | 2011-04-28 18:05:40 +0000 |
commit | d296150fac6e14469b6b97eca76c0d8f0de9241e (patch) | |
tree | 4232baff1db021769110e55f6d9db81a09976678 /lib/libm | |
parent | 7c21634f858809c1d264b0aceeaf374d68d774f4 (diff) |
- enable fenv
- add nearbyint, nearbyintf and nearbyintl implemented using fenv
Diffstat (limited to 'lib/libm')
-rw-r--r-- | lib/libm/Makefile | 17 | ||||
-rw-r--r-- | lib/libm/shlib_version | 2 | ||||
-rw-r--r-- | lib/libm/src/s_nearbyint.c | 59 |
3 files changed, 75 insertions, 3 deletions
diff --git a/lib/libm/Makefile b/lib/libm/Makefile index b7b20a1199d..ec17881fcb0 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.76 2010/07/19 12:48:23 millert Exp $ +# $OpenBSD: Makefile,v 1.77 2011/04/28 18:05:39 martynas Exp $ # $NetBSD: Makefile,v 1.28 1995/11/20 22:06:19 jtc Exp $ # # @(#)Makefile 5.1beta 93/09/24 @@ -61,6 +61,18 @@ ARCH_SRCS = e_sqrt.c e_sqrtf.c e_remainder.c e_remainderf.c \ .elif (${MACHINE_ARCH} == "sh") .PATH: ${.CURDIR}/arch/sh ARCH_SRCS = e_sqrt.c e_sqrtf.c s_fabsf.c +.elif (${MACHINE_ARCH} == "arm") +.PATH: ${.CURDIR}/arch/arm +.elif (${MACHINE_ARCH} == "hppa64") +.PATH: ${.CURDIR}/arch/hppa64 +.elif (${MACHINE_ARCH} == "m88k") +.PATH: ${.CURDIR}/arch/m88k +.elif (${MACHINE_ARCH} == "mips64") +.PATH: ${.CURDIR}/arch/mips64 +.elif (${MACHINE_ARCH} == "powerpc") +.PATH: ${.CURDIR}/arch/powerpc +.elif (${MACHINE_ARCH} == "sparc") +.PATH: ${.CURDIR}/arch/sparc .elif (${MACHINE_ARCH} == "vax") .PATH: ${.CURDIR}/arch/vax NOIEEE_ARCH = n_argred.S n_infnan.S n_sqrt.S @@ -82,6 +94,7 @@ COMMON_SRCS = b_exp__D.c b_log__D.c b_tgamma.c \ e_rem_pio2.c \ e_rem_pio2f.c e_remainder.c e_remainderf.c e_scalb.c e_scalbf.c \ e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c \ + fenv.c \ k_cos.c k_cosf.c k_rem_pio2.c k_rem_pio2f.c k_sin.c k_sinf.c \ k_tan.c k_tanf.c \ s_lround.c s_lroundf.c s_llround.c s_llroundf.c \ @@ -99,7 +112,7 @@ COMMON_SRCS = b_exp__D.c b_log__D.c b_tgamma.c \ s_floor.c s_floorf.c s_frexpf.c s_ilogb.c s_ilogbf.c \ s_log1p.c \ s_log1pf.c s_logb.c s_logbf.c s_llrint.c s_llrintf.c s_lrint.c \ - s_lrintf.c s_modff.c s_nan.c \ + s_lrintf.c s_modff.c s_nan.c s_nearbyint.c \ s_nextafter.c s_nextafterf.c s_remquo.c s_remquof.c s_rint.c \ s_rintf.c s_round.c s_roundf.c \ s_scalbln.c s_scalbn.c s_scalbnf.c s_signgam.c s_significand.c \ diff --git a/lib/libm/shlib_version b/lib/libm/shlib_version index 715ca914844..3d02023227e 100644 --- a/lib/libm/shlib_version +++ b/lib/libm/shlib_version @@ -1,2 +1,2 @@ major=5 -minor=2 +minor=3 diff --git a/lib/libm/src/s_nearbyint.c b/lib/libm/src/s_nearbyint.c new file mode 100644 index 00000000000..d299c21b07d --- /dev/null +++ b/lib/libm/src/s_nearbyint.c @@ -0,0 +1,59 @@ +/* $OpenBSD: s_nearbyint.c,v 1.1 2011/04/28 18:05:39 martynas Exp $ */ + +/* + * Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <fenv.h> +#include <math.h> + +double +nearbyint(double x) +{ + fenv_t fenv; + double res; + + feholdexcept(&fenv); + res = rint(x); + fesetenv(&fenv); + + return (res); +} + +float +nearbyintf(float x) +{ + fenv_t fenv; + float res; + + feholdexcept(&fenv); + res = rintf(x); + fesetenv(&fenv); + + return (res); +} + +long double +nearbyintl(long double x) +{ + fenv_t fenv; + long double res; + + feholdexcept(&fenv); + res = rintl(x); + fesetenv(&fenv); + + return (res); +} |