[PATCH]RE: pow() function problem with SH target
Thomas Fitzsimmons
fitzsim@redhat.com
Thu Jun 27 11:09:00 GMT 2002
On Thu, 2002-06-27 at 06:01, Anita Kulkarni wrote:
> 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.
I'm working on this bug and will commit a fix for it today.
> 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;
> ---------------------------------------------------------------------
This block is checking whether the exponent y is an integer, and if so,
whether it is even or odd. So first it checks the fractional part of
y. If it is zero, y is an integer. Then it checks the fractional part
of y * (1/2). If the fractional part is non-zero, y is odd; if it is
zero, y is even. This section of code is correct, although calling the
resulting boolean "sign" is somewhat confusing.
Tom
>
>
> -----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
> > =========================================
> >
--
Thomas Fitzsimmons
Red Hat Canada Limited e-mail: fitzsim@redhat.com
2323 Yonge Street, Suite 300
Toronto, ON M4P2C9
More information about the Newlib
mailing list