SUMM: BUG in 'modf' function ????

From: Joe Spanicek <joe_at_resptk.bhp.com.au>
Date: Mon, 7 Apr 1997 11:13:07 +1000

Hi all,

I got a quick reply that sums up the problem:

The promotion of a 'float' to 'double' is causing
the problem, so I opted to use the 'modff' function for
floats.

Thanks

PS: there is NO bug in 'modf'



> Hi Joe
>
> > Could someone confirm whether the following is a BUG
> > with the 'modf' function or me doing something wrong !!!
> > ...
> > Or does this have to do with promoting 'value1' from a float to
> > a double ???
> > In any case the 'modf' function looks like it returns '1.0' or is this
> > really '0.99999999999999999' and the printf's '%f' prints this as a 1.0 ??
>
> It's really 0.9999997169 which you can see if you change your output
> format from %f to %15.10g.
>
> Inserting this line after the calculation of x1 x2:
>
> printf ("%s %g %s %g\n", "x1-21:", x1-21,"x2-21:", x2-21);
>
> gives:
>
> x1-21: -2.83122e-07 x2-21: 0
>
> This shows the source of your problem. The value of x1 is less than
> 21 because of the lower precision of float compared with double.
>
> Cheers
> Ian
>
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
> _/ Ian Mortimer _/
> _/ Email: mortimer_at_physics.uq.edu.au ,-_|\ Department of Physics _/
> _/ Tel : +61 7 3365 3436 / *\ University of Queensland _/
> _/ Fax : +61 7 3365 1242 \_,-._/ St. Lucia, Brisbane _/
> _/ v Queensland, Australia 4072 _/
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
> Disclaimer: Any opinions expressed are my own.
>
>
Received on Mon Apr 07 1997 - 03:28:16 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:36 NZDT