From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078611110240.tru64-unix-managers.marc@archive.invalid> From: joe () resptk ! bhp ! com ! au (Joe Spanicek) Date: Mon, 07 Apr 1997 01:13:07 +0000 To: tru64-unix-managers Subject: SUMM: BUG in 'modf' function ???? X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078611110240 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@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. > >