This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]RE: pow() function problem with SH target


Hi,
If the toolchain is built with --enable-newlib-hw-fp then
in mathfp/sf_pow.c file the sign value is set depending on the return value of modff (ldexpf (y, -1), &t). But as the modff function returns integral part in t if we check this value then the problem gets solved.
The following is the patch for this. 
But it is only you people who can review and approve it.
Please review and correct me if I am wrong.
Thank you in advance.
-------------------------------------------------------------------
--- .../src/newlib-1.10.0/newlib/libm/mathfp/sf_pow.c   Mon Jun  3 13:02:27 2002
+++ .../src/newlib-1.10.0/newlib/libm/mathfp/sf_pow.new.c       Thu Jun 27 15:01
:33 2002
@@ -15,7 +15,8 @@
   k = modff (y, &d);
   if (k == 0.0)
     {
-      if (modff (ldexpf (y, -1), &t))
+      modff (ldexpf (y, -1), &t);
+      if (t)
         sign = 0;
       else
         sign = 1;                                                             
---------------------------------------------------------------------
Regards,
Anita Kulkarni



-----Original Message-----
From: Shrinivas Atre 
Sent: Monday, June 24, 2002 11:45 AM
To: newlib@sources.redhat.com
Cc: Shrinivas Atre
Subject: RE: pow() function problem with SH target


Hi,
The problem is observed only if --enable-newlib-hw-fp is given while configuring newlib.
If this option is not given then the function works fine.

Regards
Shrinivas

> -----Original Message-----
> From: Shrinivas Atre 
> Sent: Saturday, June 22, 2002 1:57 PM
> To: newlib@sources.redhat.com
> Cc: Shrinivas Atre
> Subject: pow() function problem with SH target
> 
> 
> Hi,
> On SH tool chain it is observed that the pow() function does 
> not give correct results for some conditions.
> e.g.
> a = pow(x,y); /* x raised to y */
> When y = 4.0, 6.0 or exact multiple of 2.0 then pow function 
> does not give correct result. However even if y is 0.0000001 
> less or more it gives correct result.
> 
> Test program is given at the end of mail.
> 
> Any clue , suggestions ?
> 
> The function fails only for Hitachi-SH targets whereas it 
> works well with H8300 targets.
> 
> I am using newlib 1.10.0.
> 
> Thanks in advance.
> Regards
> Shrinivas
> 
> Here is the test program.
> 
> ====================================== pow.c BEGIN  
> ==========================================
> #include <stdio.h>
> #include <math.h>
> 
> float f1,f2,f3,f4,f5,fr;
> 
> int main(void)
> {
>   f1 = 5.0;
>   f2 = 4.0;
>   f3 = 6.0;
>   f4 = 7.0;
>   f5 = 4.00000000001;
>   fr = pow(f1,f1); /* ===============> OK */
>   printf("%f raised to %f is %f \r\n",f1,f1,fr);
>   fr = pow(f1,f2); /* ===============> FAILS */
>   printf("%f raised to %f is %f \r\n",f1,f2,fr);
>   fr = pow(f1,f3); /* ===============> FAILS */
>   printf("%f raised to %f is %f \r\n",f1,f3,fr);
>   fr = pow(f1,f4); /* ===============> OK */
>   printf("%f raised to %f is %f \r\n",f1,f4,fr);
>   fr = pow(f1,f5); /* ===============> THIS IS ALSO OK */
>   printf("%f raised to %f is %f \r\n",f1,f5,fr);
>   return (int)fr;
> }
> ======================================= pow.c END 
> =========================================
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]