This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: difference in calculation result when using gcc vs Visual studio and optimisation flag
- From: Mason <slash dot tmp at free dot fr>
- To: Игорь Сотниченко <igor dot sotnichenko at gmail dot com>
- Cc: GCC help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 26 Apr 2018 08:16:58 +0200
- Subject: Re: difference in calculation result when using gcc vs Visual studio and optimisation flag
- References: <CAAo4jWMKpaw7NUFx1+=k6t_sbCvUEOMr19sjy0YB7USKcujSsw@mail.gmail.com> <553aea17-8ee3-b50b-3bad-5875eb9e6aee@free.fr> <CAAo4jWPJ9vCM9HuZDVg6PQSW076R02_6LZUhsOH1X0-RK=NQBA@mail.gmail.com>
On 26/04/2018 07:24, Игорь Сотниченко wrote:
> Thanks for the answer, a problem with floating point.
> I want to understand why disabling optimization solves the problem?
http://c-faq.com/fp/
See question 14.4a
Floating point numbers are approximations of real numbers.
For example, adding a "large" number to a "tiny" number "loses" the
precision of the tiny number. Addition is not associative.
Compilers are allowed to perform the computation in higher precision
than the actual type, which may affect the result.
If you have a lot of time on your hands, and a desire to learn,
you may also want to read:
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
Regards.