This is the mail archive of the
gsl-discuss@sourceware.org
mailing list for the GSL project.
RE: Not clear to understand :)
- From: <keith dot briggs at bt dot com>
- To: <gsl-discuss at sourceware dot org>
- Date: Thu, 22 Nov 2007 11:38:14 -0000
- Subject: RE: Not clear to understand :)
These are *not* equivalent in floating point, of course. The first is better.
Even better:
for (i = 1; i <= n; i++)
{
m_x += (x[i * xstride] - m_x) / i;
m_y += (y[i * ystride] - m_y) / i;
}
Keith
-----Original Message-----
From: gsl-discuss-owner@sourceware.org
[mailto:gsl-discuss-owner@sourceware.org]On Behalf Of Serhiy Lisovenko
Sent: 22 November 2007 11:34
To: gsl-discuss@sourceware.org
Subject: Not clear to understand :)
in file fit/linear.c
for (i = 0; i < n; i++)
{
m_x += (x[i * xstride] - m_x) / (i + 1.0);
m_y += (y[i * ystride] - m_y) / (i + 1.0);
}
and other same...
code equivalent to
for (i = 0; i < n; i++)
{
m_x +=x[i * xstride];
m_y +=y[i * ystride];
}
m_x/=(double)n;
m_y/=(double)n;
But the second code is more clear and some faster (no extra divisions).