C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

static/dynamic allocation give different floating results. S
Goto page 1, 2  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
archondas
Guest





PostPosted: Mon Jan 10, 2005 10:16 am    Post subject: static/dynamic allocation give different floating results. S Reply with quote



I have encountered a very strange behaviour
of floating point accuracy depending on the way
I allocate memory! The results are slightly different
but should they? I used the following simple program:

#include <iostream>
#include <cmath>
using namespace std;

#define STATIC_SIZE 60000000
double static_array[STATIC_SIZE];

int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "usage: " << argv[0] << " nn";
cout << "example: " << argv[0] << " 10000000n";
exit(1);
}

int n = (int) strtol(argv[1], NULL, 0);

double sum = 0.0;
double static_sum = 0.0;
double dynamic_sum = 0.0;

double* dynamic_array = new double[n];
const double pi = 4.0*atan(double(1.0));

for (int i = 0; i < n; i++)
{
double value_i = cos(pi*i/(n-1));
dynamic_array[i] = value_i;
static_array[i] = value_i;
dynamic_sum += dynamic_array[i];
static_sum += static_array[i];
sum += value_i;
}

cout.setf(ios::scientific, ios::floatfield);
cout.precision(16);
cout << "sum = " << sum << endl;
cout << "static_sum = " << static_sum << endl;
cout << "dynamic_sum = " << dynamic_sum << endl;

delete[] dynamic_array;
return 0;
}


Here is the output with g++-3.4.3 -O2
--------------------------------------
# ./run 100000
sum = 1.0667244865203429e-11
static_sum = 1.0667244865203429e-11
dynamic_sum = -3.8704595084482207e-12


# ./run 1000000
sum = -4.6566472899911560e-10
static_sum = -4.6566472899911560e-10
dynamic_sum = -3.4879821253497312e-10

# ./run 10000000
sum = 8.2471927065341788e-09
static_sum = 8.2471927065341788e-09
dynamic_sum = 8.3632101244290880e-09

# ./run 40000000
sum = -1.0021416363414914e-07
static_sum = -1.0021416363414914e-07
dynamic_sum = -1.0021962060235978e-07

exactly the same results are produced with
icc -O2 (icc version 8.1.026).

For the test I used an AMD ATHLON-XP.

Any comments?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Naveen
Guest





PostPosted: Mon Jan 10, 2005 8:07 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote



Hi archondas.
I think the discrepancy might be due to some compiler optimization. I
see that you have compiled with O2 flag.

Try compiling without the O2 flag. The results should be the same.
--
Regards
Naveen.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ron Natalie
Guest





PostPosted: Mon Jan 10, 2005 8:26 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote



archondas wrote:
Quote:
I have encountered a very strange behaviour
of floating point accuracy depending on the way
I allocate memory! The results are slightly different
but should they? I used the following simple program:


I'd have a look at the assembler. Any chance that static_sum
or dynamic_sum is being accumulated in a floating register
without being written back to memory (the registers are 80
bits wide, while the doubles are 64)?

If your compiler supports "long double" does that change the
behavior?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ulrich Eckhardt
Guest





PostPosted: Mon Jan 10, 2005 8:31 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

archondas wrote:
Quote:
I have encountered a very strange behaviour of floating point
accuracy depending on the way I allocate memory!

I doubt you can relate that to the way you allocate the memory, but see
below..

Quote:
The results are slightly different
but should they? I used the following simple program:

int n = (int) strtol(argv[1], NULL, 0);

double sum = 0.0;
double static_sum = 0.0;
double dynamic_sum = 0.0;

double* dynamic_array = new double[n];
const double pi = 4.0*atan(double(1.0));

for (int i = 0; i < n; i++)
{
double value_i = cos(pi*i/(n-1));
dynamic_array[i] = value_i;
static_array[i] = value_i;
dynamic_sum += dynamic_array[i];
static_sum += static_array[i];
sum += value_i;
}

cout.setf(ios::scientific, ios::floatfield);
cout.precision(16);
cout << "sum = " << sum << endl;
cout << "static_sum = " << static_sum << endl;
cout << "dynamic_sum = " << dynamic_sum << endl;

delete[] dynamic_array;

Your program has a mistake in the way it tests: the two arrays and the
computed sums are not handled the same. It is up to the compiler/optimizer
(and often happens) that they store floating point values with a higher
precision temporarily, in particular on IA32 some computations are done
with 80 bits precision and stored as 64 bit in memory (assuming double). If
you were fair, you would call a function with the array to fill it and
compute its sum.

Quote:
Here is the output with g++-3.4.3 -O2
--------------------------------------
# ./run 100000
sum = 1.0667244865203429e-11
static_sum = 1.0667244865203429e-11
dynamic_sum = -3.8704595084482207e-12


# ./run 1000000
sum = -4.6566472899911560e-10
static_sum = -4.6566472899911560e-10
dynamic_sum = -3.4879821253497312e-10

# ./run 10000000
sum = 8.2471927065341788e-09
static_sum = 8.2471927065341788e-09
dynamic_sum = 8.3632101244290880e-09

# ./run 40000000
sum = -1.0021416363414914e-07
static_sum = -1.0021416363414914e-07
dynamic_sum = -1.0021962060235978e-07

You might have mentioned the expected value: If interpret your code right,
it integrates cos() in the interval [0, pi], which should yield zero.
Looking at above results, I'd say they are pretty close, so that little bit
of inaccuracy should not be a problem.
When working with flots you have to be prepared for this inaccuracy anyways,
relying on exact floating-point equality produces hard to debug errors.

Quote:
exactly the same results are produced with
icc -O2 (icc version 8.1.026).

I believe that g++ by default creates code for 386, but I doubt that Intel's
compiler does so, too. Telling GCC to cater for a later architecture (with
more internal registers) could make it keep all values in registers with
higher precision, too.

Uli

--
FAQ: http://parashift.com/c++-faq-lite/

/* bittersweet C++ */
default: break;

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
archondas
Guest





PostPosted: Tue Jan 11, 2005 10:40 am    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

Ok for all of you,
here is the new code! I think it is more fair than
the previous one! Take a look!

#include <iostream>
#include <cmath>
using namespace std;

#define STATIC_SIZE 60000000
double static_array[STATIC_SIZE];

int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "usage: " << argv[0] << " nn";
cout << "example: " << argv[0] << " 10000000n";
exit(1);
}

int n = (int) strtol(argv[1], NULL, 0);

double sum = 0.0;
double static_sum = 0.0;
double dynamic_sum = 0.0;

double* dynamic_array = new double[n];
const double pi = 4.0*atan(double(1.0));

for (int i = 0; i < n; i++)
{
dynamic_array[i] = cos(pi*i/(n-1));
static_array[i] = cos(pi*i/(n-1));
}

for (int i = 0; i < n; i++)
{
double value_i = cos(pi*i/(n-1));
dynamic_sum += dynamic_array[i];
static_sum += static_array[i];
sum += value_i;
}

cout.setf(ios::scientific, ios::floatfield);
cout.precision(16);
cout << "sum = " << sum << endl;
cout << "static_sum = " << static_sum << endl;
cout << "dynamic_sum = " << dynamic_sum << endl;

delete[] dynamic_array;
return 0;
}

# ./run 1000
sum = 8.4376949871511897e-14
static_sum = 8.3488771451811772e-14
dynamic_sum = 8.3488771451811772e-14

# ./run 10000
sum = -9.6567198681896116e-13
static_sum = -5.5733195836182858e-14
dynamic_sum = -5.5733195836182858e-14

# ./run 100000
sum = 1.0667244865203429e-11
static_sum = -3.8704595084482207e-12
dynamic_sum = -3.8704595084482207e-12

# ./run 1000000
sum = -4.6566472899911560e-10
static_sum = -3.4879821253497312e-10
dynamic_sum = -3.4879821253497312e-10

# ./run 10000000
sum = 8.2471927065341788e-09
static_sum = 8.3632101244290880e-09
dynamic_sum = 8.3632101244290880e-09

# ./run 40000000
sum = -1.0021416363414914e-07
static_sum = -1.0021962060235978e-07
dynamic_sum = -1.0021962060235978e-07

Without -O2 for g++ the results are the same for all the
above cases. But as you see for very large numbers
the result is closer to zero for sum than for static_sum
or dynamic_sum. Should it? Yes of course this is
closer to the correct answer which is zero! But why isn't it
for smaller numbers? Why floating point operations loose
accuracy when storing the result in a local variable for
indices (n <10000000) and not for (n>=10000000). What changes? And guys,
why should the result depend on -O2.
Why optimizing the code should produce different results!
Let's try long double instead of double.
That worked fine! Both with or without -O2.
What is the difference guys?
icc with long double workder fine even with -O2.
icc with double behaves just like gcc giving the same
results.

Summary:
--------
Floating point addition of #n doubles is more accurate
when the doubles are read from memory for n<10000000.
Less accurate when n >= 10000000. (with -O2 enabled)

With -O2 disabled there is not difference although
the results seem to be less accurate than with -O2 enabled.

long doubles do not have such problems.


Conclusion:
-----------
Some guys should fix their -O2 implementation.
Use long doubles to be on the safe side!


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Jeroen
Guest





PostPosted: Tue Jan 11, 2005 8:52 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

This definitely has to do with the optimizations (-O2 switch) you are
using. If you compile without optimizations, you'll see there is no
difference between the three results at all, but also that the result
is different than ALL three results you get when optimizations are
turned on.

Floating point numbers have limited precision. Combined with
optimizations, this can lead to small differences in results. What
you're seeing here is a very tiny difference in the value of value_i
(Order 10^-17), accumulated over thousands of iterations.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Antoun Kanawati
Guest





PostPosted: Tue Jan 11, 2005 9:13 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

archondas wrote:
Quote:
I have encountered a very strange behaviour
of floating point accuracy depending on the way
I allocate memory! The results are slightly different
but should they? I used the following simple program:

Did you try other sequences of instructions? e.g.: reordering the "+="
statements, or doing each of the sums in a separate loop?

Your program demonstrates an issue with floating point arithmetic
that may, or may not, be related to the location of the data.

My recollection is a bit fuzzy on this subject, but I recall that
the floating point hardware may have more bits than 'double'. So,
you may be picking up leftover floating point fuzz from the floating
point registers; which has nothing to do with dynamic or static
allocation.

Your program looks like it's computing a large number of values that
should cancel each other out and give you a zero sum: the sum of
cosines of angles between 0 and pi, in uniform steps. This set of
angles is symmetric around pi/2, and cos(x) = -cos(x+pi/2); so, your
total, in theory, should be zero.

Yet, none of the sums you show are zero; and, the magnitude of the sum
increases (i.e.: accumulated error). Also, these sums are converging
as you increase n, suggesting two contributions to the accumulated error
with different characteristics. In theory, the only source of FP error
should result from adding/subtracting values of greatly different
magnitudes, which is exactly what you have here: the values near pi/2
are very close to 0, but by the time you get near pi/2, the sum is
substantially larger than 0; on the other size of pi/2, you have a
similar situation with the magnitudes.

And, of course, although cos() is supposed to be symmetric around pi/2,
in practice, this simply means "modulo epsilon".

# ./run 100000
sum = 1.0667244865203429e-11
static_sum = 1.0667244865203429e-11
dynamic_sum = -3.8704595084482207e-12


# ./run 1000000
sum = -4.6566472899911560e-10
static_sum = -4.6566472899911560e-10
dynamic_sum = -3.4879821253497312e-10

# ./run 10000000
sum = 8.2471927065341788e-09
static_sum = 8.2471927065341788e-09
dynamic_sum = 8.3632101244290880e-09

# ./run 40000000
sum = -1.0021416363414914e-07
static_sum = -1.0021416363414914e-07
dynamic_sum = -1.0021962060235978e-07

[snipped program follows]
Quote:
#define STATIC_SIZE 60000000
double static_array[STATIC_SIZE];

double sum = 0.0;
double static_sum = 0.0;
double dynamic_sum = 0.0;

double* dynamic_array = new double[n];
const double pi = 4.0*atan(double(1.0));

for (int i = 0; i < n; i++)
{
double value_i = cos(pi*i/(n-1));
dynamic_array[i] = value_i;
static_array[i] = value_i;
dynamic_sum += dynamic_array[i];
static_sum += static_array[i];
sum += value_i;
}

cout << "sum = " << sum << endl;
cout << "static_sum = " << static_sum << endl;
cout << "dynamic_sum = " << dynamic_sum << endl;

--
A. Kanawati
[email]NO.antounk.SPAM (AT) comcast (DOT) net[/email]

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
pierrebai@hotmail.com
Guest





PostPosted: Tue Jan 11, 2005 10:43 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

It is not possible to be certain without looking at the disassembly,
but I would suspect that the static array value is not reloaded after
the store while the dynamic value is. Must be optimized because the
static array is visible.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Ron Natalie
Guest





PostPosted: Tue Jan 11, 2005 11:45 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

archondas wrote:

Quote:
Let's try long double instead of double.
That worked fine! Both with or without -O2.
What is the difference guys?

I told you what the difference was in response to your

first post. You're adding up a million tiny numbers
in differing precisions. Yes, you get different answers.
Floating point doesn't mean infinite precision. There
is a difference in using 80 bit and 64 variables.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
archondas
Guest





PostPosted: Thu Jan 13, 2005 4:40 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

Dear Ron,
I do not know from which scientific area you come
from, but have in mind that the slightest change
in floating point numbers can have a great impact
when somebody is trying to solve a very ill-conditioned
linear system. Such systems arise from direct solution
methods applied in scattering problems.

So as for the million floating point values, let
me ask you something. Should it make a difference
when adding from a static allocated vector or from
a dynamic allocated one? Should those result be different
when adding directly to a variable? I think not!
Adding millions of values should only make a difference
for the outcome of the addition. In our case the result
is zero but the outcome of the addition is not zero.
This type of error has to do with the 64-80 bit of FPU
registers. But when you are using a specific type
double, long double, then, each floating point
truncation error when converting cos(something) to
a number is always the same and depends on the value of
cos(something). Having that in mind the results from
our example should always be the same! Why they are not
when we are using type double and -O2 switch is something
we are investigating here! As you remember -O switch gives
as everywhere the same results. What changes with -O2?

You said
--------
Quote:
There is a difference in using 80 bit and 64 variables!

Of course there is. But answer to that question:

variables like: double var;
double array_static[10];
double* array_dynamic = new double[10];

do those things above have 64bit or 80bit representation?
Even if they did have different representation,
then since we are adding them using a variable which
calculates the sum at the end they are truncated to the
64bit or whatever representation of the variable! And
remember -O delivers correct results but -O2 doesn't.

So what you claim up there I think is not the
cause of our problem!

Any other ideas?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ulrich Eckhardt
Guest





PostPosted: Sat Jan 15, 2005 3:20 am    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

archondas wrote:
Quote:
I do not know from which scientific area you come
from, but have in mind that the slightest change
in floating point numbers can have a great impact
when somebody is trying to solve a very ill-conditioned
linear system. Such systems arise from direct solution
methods applied in scattering problems.

Relying on ultimate precision is therefore already broken. You might
consider a scientific computing library for that.

Quote:
So as for the million floating point values, let
me ask you something. Should it make a difference
when adding from a static allocated vector or from
a dynamic allocated one?

It doesn't, as you have demonstrated yourself by handling both sufficiently
equal. Remember, your first example didn't handle them equally and your
second one still didn't, which is why I said 'sufficiently'.

Quote:
Should those result be different when adding directly to a variable?
I think not!

Imagine this:
x = a + b + c

Written in C++ this becomes:
float x = a + b + c;

Mathematically, this equation it valid:
(a + b) + c = a + (b + c)

but imagine the computation with limited precision in C++:

float a = 100000.0f;
float b = -100000.0f;
float c = 0.0000042f;

(a + b) + c; // yields something close to c
a + (b + c); // yields zero, c vanished in b's precision

Quote:
Adding millions of values should only make a difference
for the outcome of the addition. In our case the result
is zero but the outcome of the addition is not zero.
This type of error has to do with the 64-80 bit of FPU
registers. But when you are using a specific type
double, long double, then, each floating point
truncation error when converting cos(something) to
a number is always the same and depends on the value of
cos(something). Having that in mind the results from
our example should always be the same! Why they are not
when we are using type double and -O2 switch is something
we are investigating here! As you remember -O switch gives
as everywhere the same results. What changes with -O2?

Look at the assembly. Typically, unoptimised compilation yields assembly
that almost exactly looks like the C++ code you wrote. Optimised code
however tries to make best use of the processor's registers, i.e. whenever
possible, it keeps an intermediate result in a register. Apart from being
faster, this also yields an increased precision for floating-point
operations.

Yes, the net results change, but if your computation relies on exact
comparison of floating-point values, your program is broken anyway. This is
really old lore that floating-point computations yield a certain error and
that this error changes with external influences that are outside your
control. There is nothing wrong with it, you will have to adapt your
wetware to these facts first and then your software.


Uli

--
FAQ: http://parashift.com/c++-faq-lite/

/* bittersweet C++ */
default: break;

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ron Natalie
Guest





PostPosted: Sun Jan 16, 2005 4:46 am    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

archondas wrote:
Quote:
Dear Ron,
I do not know from which scientific area you come
from, but have in mind that the slightest change
in floating point numbers can have a great impact
when somebody is trying to solve a very ill-conditioned
linear system. Such systems arise from direct solution
methods applied in scattering problems.

I come from and engineering and computer background.
In both disciplines we understand that it is usually
not possible to have an exact representation of a value.
You always have some accuracy limitations either in the
measurement, or the calculations that result. It is just
as important as calculating the value of an a formula
to also calculate it's accuracy.

Any scientific or engineering discipline will tell you that.
If your measurement accuracy is 1 ppm and you've got value in
the range of 100 km, you can't go adding millimeters to it.


I might suggest a course or at least a text in numerical
methods.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
archondas
Guest





PostPosted: Mon Jan 17, 2005 9:12 am    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

Dear Ron,
Now it is clear why you cannot understand the importance
of the accuracy in floating point calculations! Engineers
usually are satisfied if they have achieved the solution
with an error of 10%. In my case in order to achieve
acceptable results then you have to solve the linear system
as much accurately as possible. So I think that it is clear why changes in
the results like those I described above are not acceptable!

On the other hand here we are examining whether memory
allocation in one way or another should influence
or not the results and under which circumstances the
results are as much accurate as possible(register variables, memory
variables ...). So discussing whether millimiters
make a difference when we are measuring kilometers is neither C++ nor a
compiler issue! You should address this
in some other (list or forum).


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Francis Glassborow
Guest





PostPosted: Mon Jan 17, 2005 8:19 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

In article
<17606844081197021a9833e0822d3c3e (AT) localhost (DOT) talkaboutprogramming.com>,
archondas <dkouroun (AT) cc (DOT) uoi.gr> writes
Quote:
Dear Ron,
Now it is clear why you cannot understand the importance
of the accuracy in floating point calculations! Engineers
usually are satisfied if they have achieved the solution
with an error of 10%.

No an engineer wants to estimate the accuracy and then determine if that
is acceptable in context. For example, when building an electrical
circuit it is often acceptable that a specific resistance is within 20%
of nominal, but at other times a much higher level of accuracy is
required (one at considerable extra cost)

Quote:
In my case in order to achieve
acceptable results then you have to solve the linear system
as much accurately as possible.

No, you do not. You need to solve the linear system within a specified
level of accuracy. Until you can specify the costs and benefits of
accuracy you are not ready to cut code.

Quote:
So I think that it is clear why changes in
the results like those I described above are not acceptable!

No, the only accuracy you are entitled to assume is that guaranteed by
the language, or by the library vendor. An engineer (or applied
mathematician) will be able to calculate both the maximum possible
errors and the expected error with given confidence levels. Running code
in marginally different environments tells you nothing useful about how
similar code will behave.



--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Tue Jan 18, 2005 11:13 pm    Post subject: Re: static/dynamic allocation give different floating result Reply with quote

archondas wrote:
Quote:
Dear Ron,

Now it is clear why you cannot understand the importance of
the accuracy in floating point calculations!

Where did Ron say he didn't understand the importance of
accuracy? What Ron said is simply that computer math has a
special set of rules, and unless you understand them and program
to them, you won't get acceptable results.

Quote:
Engineers usually are satisfied if they have achieved the
solution with an error of 10%.

Engineers are satisfied when they achieve the required accuracy.
Whatever that is. (In the inertial guidance systems of the
Airbus, they are allowed one meter error for a flight from
Toulouse to New York. That's a lot less than 10% -- something
around 1 in 10 million, I think.)

Quote:
In my case in order to achieve acceptable results then you
have to solve the linear system as much accurately as
possible. So I think that it is clear why changes in the
results like those I described above are not acceptable!

So don't use a computer; do it by hand. The fact is that
computers have no data type "real". Computer floating point
follows its own rules; if you use it, you have to obey its
rules, because they aren't going to change.

And of course, no one said that the rules make the problem
simple. I'm not familiar with the details, but I know that
there are different techniques for summing the terms of a
sequence, which can be used to reduce the error. Numericists
know about them. Others probably should not be using floating
point for anything but the simplest calculations.

Quote:
On the other hand here we are examining whether memory
allocation in one way or another should influence or not the
results and under which circumstances the results are as much
accurate as possible(register variables, memory variables...).

Are we? For the moment, I've seen no indication that memory
allocation has any effect on the results. Too many other
variables involved.

What can affect results is whether the intermediate values are
stored in memory or not. And that in turn can depend on the
level of optimization.

Before going any farther, I would strongly recommend that you
read http://docs.sun.com/source/806-3568/ncg_goldberg.html. You
might also want to check out the addendum as well
([url]http://cch.loria.fr/documentation/IEEE754/ACM/addendum.html)[/url],
particularly the section "Pitfalls in Computations on
Extended-Based Systems". Until you've read and understood the
implications of these papers, there's really no point in further
discussion.

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.