Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Aug 1996 15:43:57 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-hackers@FreeBSD.org, voisine@cioe.com
Subject:   Re: rintf broke?
Message-ID:  <199608240543.PAA16214@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>Umm... is the rintf function broken or what?

>...
>    cout << rintf(12.3456789) << endl;
>...

>here's the output:

>12.125

Yes, it is broken.  printf("%g", rintf(12.3456789) also gives 12.125.

I wouldn't use the float-precision functions.  hypotf() and powf() are
also broken.  acosf(), asinf() and atan2f() have small errors and are
slower than the corresponding double-precision functions if the hardware
versions are used.

Here are some fixes.   They have been tested a lot using `ucbtest' but
haven't been used much.  `ucbtest' apparently doesn't test rintf().

Bruce

diff -c2 src/lib/msun/src/e_acosf.c~ src/lib/msun/src/e_acosf.c
*** src/lib/msun/src/e_acosf.c~	Wed May 31 19:12:47 1995
--- src/lib/msun/src/e_acosf.c	Wed May 31 19:15:41 1995
***************
*** 27,33 ****
  #endif
  one =  1.0000000000e+00, /* 0x3F800000 */
! pi =  3.1415925026e+00, /* 0x40490fda */
! pio2_hi =  1.5707962513e+00, /* 0x3fc90fda */
! pio2_lo =  7.5497894159e-08, /* 0x33a22168 */
  pS0 =  1.6666667163e-01, /* 0x3e2aaaab */
  pS1 = -3.2556581497e-01, /* 0xbea6b090 */
--- 27,33 ----
  #endif
  one =  1.0000000000e+00, /* 0x3F800000 */
! pi =  3.1415927410e+00, /* 0x40490fdb */
! pio2_hi =  1.5707963705e+00, /* 0x3fc90fdb */
! pio2_lo = -4.3711388287e-08, /* 0xb33bbd2e */
  pS0 =  1.6666667163e-01, /* 0x3e2aaaab */
  pS1 = -3.2556581497e-01, /* 0xbea6b090 */
diff -c2 src/lib/msun/src/e_asinf.c~ src/lib/msun/src/e_asinf.c
*** src/lib/msun/src/e_asinf.c~	Sat Jul 13 18:31:41 1996
--- src/lib/msun/src/e_asinf.c	Sat Jul 13 18:31:41 1996
***************
*** 28,34 ****
  one =  1.0000000000e+00, /* 0x3F800000 */
  huge =  1.000e+30,
! pio2_hi =  1.5707962513e+00, /* 0x3fc90fda */
! pio2_lo =  7.5497894159e-08, /* 0x33a22168 */
  pio4_hi =  7.8539818525e-01, /* 0x3f490fdb */
  	/* coefficient for R(x^2) */
  pS0 =  1.6666667163e-01, /* 0x3e2aaaab */
--- 28,35 ----
  one =  1.0000000000e+00, /* 0x3F800000 */
  huge =  1.000e+30,
! pio2_hi =  1.5707963705e+00, /* 0x3fc90fdb */
! pio2_lo = -4.3711388287e-08, /* 0xb33bbd2e */
  pio4_hi =  7.8539818525e-01, /* 0x3f490fdb */
+ 
  	/* coefficient for R(x^2) */
  pS0 =  1.6666667163e-01, /* 0x3e2aaaab */
diff -c2 src/lib/msun/src/e_atan2f.c~ src/lib/msun/src/e_atan2f.c
*** src/lib/msun/src/e_atan2f.c~	Wed May 31 19:12:50 1995
--- src/lib/msun/src/e_atan2f.c	Wed May 31 19:16:01 1995
***************
*** 30,35 ****
  pi_o_4  = 7.8539818525e-01, /* 0x3f490fdb */
  pi_o_2  = 1.5707963705e+00, /* 0x3fc90fdb */
! pi      = 3.1415925026e+00, /* 0x40490fda */
! pi_lo   = 1.5099578832e-07; /* 0x34222168 */
  
  #ifdef __STDC__
--- 30,35 ----
  pi_o_4  = 7.8539818525e-01, /* 0x3f490fdb */
  pi_o_2  = 1.5707963705e+00, /* 0x3fc90fdb */
! pi      = 3.1415927410e+00, /* 0x40490fdb */
! pi_lo   = -8.7422776573e-08; /* 0xb3bbbd2e */
  
  #ifdef __STDC__
diff -c2 src/lib/msun/src/e_hypotf.c~ src/lib/msun/src/e_hypotf.c
*** src/lib/msun/src/e_hypotf.c~	Wed May 31 19:12:56 1995
--- src/lib/msun/src/e_hypotf.c	Wed May 31 19:16:16 1995
***************
*** 47,52 ****
  	       return w;
  	   }
! 	   /* scale a and b by 2**-60 */
! 	   ha -= 0x5d800000; hb -= 0x5d800000;	k += 60;
  	   SET_FLOAT_WORD(a,ha);
  	   SET_FLOAT_WORD(b,hb);
--- 47,52 ----
  	       return w;
  	   }
! 	   /* scale a and b by 2**-68 */
! 	   ha -= 0x22000000; hb -= 0x22000000;	k += 68;
  	   SET_FLOAT_WORD(a,ha);
  	   SET_FLOAT_WORD(b,hb);
***************
*** 55,66 ****
  	    if(hb <= 0x007fffff) {	/* subnormal b or 0 */
  	        if(hb==0) return a;
! 		SET_FLOAT_WORD(t1,0x3f000000);	/* t1=2^126 */
  		b *= t1;
  		a *= t1;
  		k -= 126;
! 	    } else {		/* scale a and b by 2^60 */
! 	        ha += 0x5d800000; 	/* a *= 2^60 */
! 		hb += 0x5d800000;	/* b *= 2^60 */
! 		k -= 60;
  		SET_FLOAT_WORD(a,ha);
  		SET_FLOAT_WORD(b,hb);
--- 55,66 ----
  	    if(hb <= 0x007fffff) {	/* subnormal b or 0 */
  	        if(hb==0) return a;
! 		SET_FLOAT_WORD(t1,0x7e800000);	/* t1=2^126 */
  		b *= t1;
  		a *= t1;
  		k -= 126;
! 	    } else {		/* scale a and b by 2^68 */
! 	        ha += 0x22000000; 	/* a *= 2^68 */
! 		hb += 0x22000000;	/* b *= 2^68 */
! 		k -= 68;
  		SET_FLOAT_WORD(a,ha);
  		SET_FLOAT_WORD(b,hb);
diff -c2 src/lib/msun/src/e_powf.c~ src/lib/msun/src/e_powf.c
*** src/lib/msun/src/e_powf.c~	Wed May 31 19:13:02 1995
--- src/lib/msun/src/e_powf.c	Wed May 31 19:16:23 1995
***************
*** 49,53 ****
--- 49,57 ----
  lg2  =  6.9314718246e-01, /* 0x3f317218 */
  lg2_h  =  6.93145752e-01, /* 0x3f317200 */
+ #if 0
+ lg2_l  =  1.42860677e-06, /* 0x35bfbe8e */
+ #else
  lg2_l  =  1.42860654e-06, /* 0x35bfbe8c */
+ #endif
  ovt =  4.2995665694e-08, /* -(128-log2(ovfl+.5ulp)) */
  cp    =  9.6179670095e-01, /* 0x3f76384f =2/(3ln2) */
***************
*** 168,174 ****
  	    s_h = s;
  	    GET_FLOAT_WORD(is,s_h);
! 	    SET_FLOAT_WORD(s_h,is&0xfffff000);
  	/* t_h=ax+bp[k] High */
! 	    SET_FLOAT_WORD(t_h,((ix>>1)|0x20000000)+0x0040000+(k<<21));
  	    t_l = ax - (t_h-bp[k]);
  	    s_l = v*((u-s_h*t_h)-s_h*t_l);
--- 172,178 ----
  	    s_h = s;
  	    GET_FLOAT_WORD(is,s_h);
! 	    SET_FLOAT_WORD(s_h,is&0xfffc0000);
  	/* t_h=ax+bp[k] High */
! 	    SET_FLOAT_WORD(t_h,((ix>>1)|0x20000000)+0x00400000+(k<<21));
  	    t_l = ax - (t_h-bp[k]);
  	    s_l = v*((u-s_h*t_h)-s_h*t_l);
***************
*** 237,241 ****
  	t = p_l+p_h;
  	GET_FLOAT_WORD(is,t);
! 	SET_FLOAT_WORD(t,is&0xfffff000);
  	u = t*lg2_h;
  	v = (p_l-(t-p_h))*lg2+t*lg2_l;
--- 241,245 ----
  	t = p_l+p_h;
  	GET_FLOAT_WORD(is,t);
! 	SET_FLOAT_WORD(t,is&0xfffffff8);
  	u = t*lg2_h;
  	v = (p_l-(t-p_h))*lg2+t*lg2_l;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608240543.PAA16214>