public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/61668] Division returns an error in some cases
       [not found] <bug-61668-4@http.gcc.gnu.org/bugzilla/>
@ 2014-07-02  9:51 ` redi at gcc dot gnu.org
  2014-07-02  9:52 ` ketelbinkje at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-02  9:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Actually maybe 0.59 can be represented exactly, but that doesn't change the
fact that floating point numbers are not exact and calculations can accumulate
errors.

If you really think this is a compiler bug then please provide the information
requested at https://gcc.gnu.org/bugs not screenshots.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/61668] Division returns an error in some cases
       [not found] <bug-61668-4@http.gcc.gnu.org/bugzilla/>
  2014-07-02  9:51 ` [Bug c++/61668] Division returns an error in some cases redi at gcc dot gnu.org
@ 2014-07-02  9:52 ` ketelbinkje at gmail dot com
  2014-07-02  9:58 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: ketelbinkje at gmail dot com @ 2014-07-02  9:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

Peter Ketel <ketelbinkje at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |critical

--- Comment #4 from Peter Ketel <ketelbinkje at gmail dot com> ---
(In reply to Jonathan Wakely from comment #2)
> Floating point numbers are not exact. 0.59 cannot be exactly represented in
> a 64-bit double.

Which will render the the compiler useless because I cann't predict when a
number can't be written in 64 bit double format. All computations need to be
error free. Calculator will return the correct result no matter what!

If this isn't accepted as a bug then all computations done by programs based on
this compiler can no longer be trusted.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/61668] Division returns an error in some cases
       [not found] <bug-61668-4@http.gcc.gnu.org/bugzilla/>
  2014-07-02  9:51 ` [Bug c++/61668] Division returns an error in some cases redi at gcc dot gnu.org
  2014-07-02  9:52 ` ketelbinkje at gmail dot com
@ 2014-07-02  9:58 ` redi at gcc dot gnu.org
  2014-07-02  9:59 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-02  9:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Please read http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
before making silly claims.


I don't know any compiler that will print 0.59 for this program:

extern "C" int printf(const char*, ...);

int main()
{
  printf("%.32f\n", 0.59);
}


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/61668] Division returns an error in some cases
       [not found] <bug-61668-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2014-07-02  9:58 ` redi at gcc dot gnu.org
@ 2014-07-02  9:59 ` redi at gcc dot gnu.org
  2014-07-02 10:03 ` schwab@linux-m68k.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-02  9:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
See also https://gcc.gnu.org/bugs/#nonbugs


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/61668] Division returns an error in some cases
       [not found] <bug-61668-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2014-07-02  9:59 ` redi at gcc dot gnu.org
@ 2014-07-02 10:03 ` schwab@linux-m68k.org
  2014-07-04  7:36 ` ketelbinkje at gmail dot com
  2014-07-04  8:36 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 7+ messages in thread
From: schwab@linux-m68k.org @ 2014-07-02 10:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

--- Comment #7 from Andreas Schwab <schwab@linux-m68k.org> ---
Don't try to emulate decimal arithmetics with binary arithmetics.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/61668] Division returns an error in some cases
       [not found] <bug-61668-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2014-07-02 10:03 ` schwab@linux-m68k.org
@ 2014-07-04  7:36 ` ketelbinkje at gmail dot com
  2014-07-04  8:36 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 7+ messages in thread
From: ketelbinkje at gmail dot com @ 2014-07-04  7:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

--- Comment #8 from Peter Ketel <ketelbinkje at gmail dot com> ---
So what is the use of a math library that is only capable of binary
computations?
In the real world we use the decimal system for all computations.

Do we need binary computations? In most cases NO.

What is the use of a real or double if it's only capable to approximate
a decimal fraction?

This piece of code will calculate the value for s correctly on a IBM
mainframe. Please note that this code was written 1966!

C AREA OF A TRIANGLE - HERON'S FORMULA

C INPUT - CARD READER UNIT 5, INTEGER INPUT

C OUTPUT - LINE PRINTER UNIT 6, REAL OUTPUT

C INPUT ERROR DISPAY ERROR OUTPUT CODE 1 IN JOB
CONTROL LISTING

      INTEGER A,B,C

      READ(5,501) A,B,C

  501 FORMAT(3I5)

      IF(A.EQ.0 .OR. B.EQ.0 .OR. C.EQ.0) STOP 1

      S = (A + B + C) / 2.0

      AREA = SQRT( S * (S - A) * (S - B) * (S -
C))

      WRITE(6,601) A,B,C,AREA

  601 FORMAT(4H A= ,I5,5H  B= ,I5,5H  C= ,I5,8H 
AREA= ,F10.2,12HSQUARE UNITS)

      STOP

      END


This is the modern Fortan test program:

program main

  implicit none
  integer re_i
  real :: Test =0.59

  Test = (0.45 + 0.45 + 0.28) / 2

  re_i = system("pause")

end

It wil fail to compute the correct value because it too uses binary
computation.
So why do we have real and double data types for computational purposes
that will never return a correct result?

Thank God we didn't use the crappy compilers anno 2014 when we flew to
the moon.


On 02-07-14 12:03, schwab@linux-m68k.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668
>
> --- Comment #7 from Andreas Schwab <schwab@linux-m68k.org> ---
> Don't try to emulate decimal arithmetics with binary arithmetics.
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/61668] Division returns an error in some cases
       [not found] <bug-61668-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2014-07-04  7:36 ` ketelbinkje at gmail dot com
@ 2014-07-04  8:36 ` redi at gcc dot gnu.org
  6 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2014-07-04  8:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Please go and complain somewhere else, it's not GCC's problem that you are
surprised by the behaviour of binary floating point logic.

There are several ways to work with exact decimal numbers. See
https://gcc.gnu.org/onlinedocs/gcc/Decimal-Float.html for one option. Another
is a maths library such a GMP for working with rational numbers. Another is
working with integers and scaling them in your code.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-04  8:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-61668-4@http.gcc.gnu.org/bugzilla/>
2014-07-02  9:51 ` [Bug c++/61668] Division returns an error in some cases redi at gcc dot gnu.org
2014-07-02  9:52 ` ketelbinkje at gmail dot com
2014-07-02  9:58 ` redi at gcc dot gnu.org
2014-07-02  9:59 ` redi at gcc dot gnu.org
2014-07-02 10:03 ` schwab@linux-m68k.org
2014-07-04  7:36 ` ketelbinkje at gmail dot com
2014-07-04  8:36 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).