From: martynas Date: Thu, 17 Jul 2008 15:36:28 +0000 (+0000) Subject: properly raise inexact; ok millert@ X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a93b996ba4666d2b81f8520a3028eccddf1c5222;p=openbsd properly raise inexact; ok millert@ --- diff --git a/lib/libm/noieee_src/n_atan2.c b/lib/libm/noieee_src/n_atan2.c index 35cc0d9e94f..873946aabf2 100644 --- a/lib/libm/noieee_src/n_atan2.c +++ b/lib/libm/noieee_src/n_atan2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: n_atan2.c,v 1.8 2008/06/21 08:26:19 martynas Exp $ */ +/* $OpenBSD: n_atan2.c,v 1.9 2008/07/17 15:36:28 martynas Exp $ */ /* $NetBSD: n_atan2.c,v 1.1 1995/10/10 23:36:37 ragge Exp $ */ /* * Copyright (c) 1985, 1993 @@ -225,9 +225,10 @@ begin: /* t is in [0,7/16] */ case 0: case 1: - if (t < small) - { big + small ; /* raise inexact flag */ - return (copysign((signx>zero)?t:PI-t,signy)); } + if (t < small) { + if (big + small > 0.0) /* raise inexact flag */ + return (copysign((signx>zero)?t:PI-t,signy)); + } hi = zero; lo = zero; break; @@ -260,9 +261,10 @@ begin: if (t <= big) t = - x / y; /* t is in [big, INF] */ - else - { big+small; /* raise inexact flag */ - t = zero; } + else { + if (big + small > 0.0) /* raise inexact flag */ + t = zero; + } } /* end of argument reduction */ diff --git a/lib/libm/noieee_src/n_cabs.c b/lib/libm/noieee_src/n_cabs.c index d1c913fd702..d3dc5964cbb 100644 --- a/lib/libm/noieee_src/n_cabs.c +++ b/lib/libm/noieee_src/n_cabs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: n_cabs.c,v 1.9 2008/06/25 17:49:31 martynas Exp $ */ +/* $OpenBSD: n_cabs.c,v 1.10 2008/07/17 15:36:28 martynas Exp $ */ /* $NetBSD: n_cabs.c,v 1.1 1995/10/10 23:36:39 ragge Exp $ */ /* * Copyright (c) 1985, 1993 @@ -122,9 +122,10 @@ hypot(double x, double y) if(x == zero) return(zero); if(y == zero) return(x); exp= logb(x); - if(exp-(int)logb(y) > ibig ) - /* raise inexact flag and return |x| */ - { one+small; return(x); } + if (exp - (int)logb(y) > ibig) { + if (one + small >= 1.0) /* raise inexact flag */ + return(x); /* return |x| */ + } /* start computing sqrt(x^2 + y^2) */ r=x-y; @@ -204,9 +205,10 @@ hypot(double x, double y) if(y == zero) return(x); exp= logb(x); x=scalbn(x,-exp); - if(exp-(int)logb(y) > ibig ) - /* raise inexact flag and return |x| */ - { one+small; return(scalbn(x,exp)); } + if (exp - (int)logb(y) > ibig) { + if (one + small >= 1.0) /* raise inexact flag */ + return(scalbn(x,exp)); /* return |x| */ + } else y=scalbn(y,-exp); return(scalbn(sqrt(x*x+y*y),exp)); } diff --git a/lib/libm/noieee_src/n_exp__E.c b/lib/libm/noieee_src/n_exp__E.c index 039427219ae..9fd13ada83a 100644 --- a/lib/libm/noieee_src/n_exp__E.c +++ b/lib/libm/noieee_src/n_exp__E.c @@ -1,4 +1,4 @@ -/* $OpenBSD: n_exp__E.c,v 1.6 2008/06/21 08:26:19 martynas Exp $ */ +/* $OpenBSD: n_exp__E.c,v 1.7 2008/07/17 15:36:28 martynas Exp $ */ /* $NetBSD: n_exp__E.c,v 1.1 1995/10/10 23:36:45 ragge Exp $ */ /* * Copyright (c) 1985, 1993 @@ -129,7 +129,11 @@ __exp__E(double x, double c) /* end of |x| > small */ else { - if(x!=zero) one+small; /* raise the inexact flag */ - return(copysign(zero,x)); + if(x != zero) { + if (one + small >= 1.0) /* raise the inexact flag */ + return(copysign(zero,x)); + } + else + return(copysign(zero,x)); } } diff --git a/lib/libm/noieee_src/n_support.c b/lib/libm/noieee_src/n_support.c index 947ca0037b2..84b2547cd20 100644 --- a/lib/libm/noieee_src/n_support.c +++ b/lib/libm/noieee_src/n_support.c @@ -1,4 +1,4 @@ -/* $OpenBSD: n_support.c,v 1.12 2008/07/16 15:25:51 martynas Exp $ */ +/* $OpenBSD: n_support.c,v 1.13 2008/07/17 15:36:28 martynas Exp $ */ /* $NetBSD: n_support.c,v 1.1 1995/10/10 23:37:06 ragge Exp $ */ /* * Copyright (c) 1985, 1993 @@ -515,7 +515,7 @@ newsqrt(double x) t=x/y; /* ...chopped quotient, possibly inexact */ j=swapINX(i); /* ...read and restore inexact flag */ if(j==0) { if(t==y) goto end; else t=subc(t); } /* ...t=t-ulp */ - b54+0.1; /* ..trigger inexact flag, sqrt(x) is inexact */ + x=b54+0.1; /* ..trigger inexact flag, sqrt(x) is inexact */ if(r==RN) t=addc(t); /* ...t=t+ulp */ else if(r==RP) { t=addc(t);y=addc(y);}/* ...t=t+ulp;y=y+ulp; */ y=y+t; /* ...chopped sum */ diff --git a/lib/libm/noieee_src/n_tanh.c b/lib/libm/noieee_src/n_tanh.c index d21d4e88916..2933b8b23a3 100644 --- a/lib/libm/noieee_src/n_tanh.c +++ b/lib/libm/noieee_src/n_tanh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: n_tanh.c,v 1.7 2008/06/21 08:26:19 martynas Exp $ */ +/* $OpenBSD: n_tanh.c,v 1.8 2008/07/17 15:36:28 martynas Exp $ */ /* $NetBSD: n_tanh.c,v 1.1 1995/10/10 23:37:08 ragge Exp $ */ /* * Copyright (c) 1985, 1993 @@ -88,8 +88,10 @@ tanh(double x) return(copysign(one-two/(expm1(x+x)+two),sign)); else if ( x > small ) {t= -expm1(-(x+x)); return(copysign(t/(two-t),sign));} - else /* raise the INEXACT flag for non-zero x */ - {big+x; return(copysign(x,sign));} + else { /* raise the INEXACT flag for non-zero x */ + t = big + x; + return(copysign(x,sign) - (t-(big+x))); + } else if(finite(x)) return (sign+1.0E-37); /* raise the INEXACT flag */ else