[Bug c++/61668] New: Division returns an error in some cases

2014-07-02 Thread ketelbinkje at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

Bug ID: 61668
   Summary: Division returns an error in some cases
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: critical
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ketelbinkje at gmail dot com

Created attachment 33043
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33043&action=edit
A screen shot of the moment the error was detected

The issue:
The program wants to divide 59 by 100. The expected result is 0.59. The program
returns 0.58997. The next division r = dSeconds / (1000 * pow(10,
ceil(log10(x returns the correct result.

Hardware:
HP 4600
Platform: Linux Mint 17 Cinnamon 64-bit
Cinamon version 2.2.13
Linux kernel 3.13.0-24-generic
Intel Xeon CPU 5140
Memory 7,8 GiB

Compiler and IDE:
g++ compiler version 4.8.2.
Code Blocks 13.12


The build log:

-- Clean: Debug in GCD (compiler: GNU GCC Compiler)---

Cleaned "GCD - Debug"

-- Build: Debug in GCD (compiler: GNU GCC Compiler)---

g++ -Wundef -Wunreachable-code -Weffc++ -std=c++11 -Wextra -Wall -g
-fexceptions -Wundef -Wunreachable-code -Wmissing-declarations -Wswitch-enum
-Wswitch-default -Weffc++ -std=c++11 -g  -c
/home/fradiavolo/Projects/GCD/c_circlenavigation.cpp -o
obj/Debug/c_circlenavigation.o
In file included from /home/fradiavolo/Projects/GCD/c_circlenavigation.h:4:0,
 from /home/fradiavolo/Projects/GCD/c_circlenavigation.cpp:1:
/home/fradiavolo/Projects/GCD/geotools.h:57:54: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const double m_Degrees_2_Radians(const double);
  ^
/home/fradiavolo/Projects/GCD/geotools.h:58:54: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const double m_Radians_2_Degrees(const double);
  ^
In file included from /home/fradiavolo/Projects/GCD/c_circlenavigation.h:4:0,
 from /home/fradiavolo/Projects/GCD/c_circlenavigation.cpp:1:
/home/fradiavolo/Projects/GCD/geotools.h:61:165: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const bool m_Correct_GeoCoordinate(const string sCoordinate = "",
const CoordinateType::CoordinateProperty t =
CoordinateType::CoordinateProperty::Undefined);
   
   
 ^
/home/fradiavolo/Projects/GCD/geotools.h:64:169: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const double m_ConvertCordinate_2_Double(const string sGeoCoordinate,
const CoordinateType::CoordinateProperty t =
CoordinateType::CoordinateProperty::Undefined);
   
   
 ^
/home/fradiavolo/Projects/GCD/geotools.h:67:34: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const bool m_ErrFlag(void) {return ErrFlag; };
  ^
g++ -Wundef -Wunreachable-code -Weffc++ -std=c++11 -Wextra -Wall -g
-fexceptions -Wundef -Wunreachable-code -Wmissing-declarations -Wswitch-enum
-Wswitch-default -Weffc++ -std=c++11 -g  -c
/home/fradiavolo/Projects/GCD/geotools.cpp -o obj/Debug/geotools.o
In file included from /home/fradiavolo/Projects/GCD/geotools.cpp:1:0:
/home/fradiavolo/Projects/GCD/geotools.h:57:54: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const double m_Degrees_2_Radians(const double);
  ^
/home/fradiavolo/Projects/GCD/geotools.h:58:54: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const double m_Radians_2_Degrees(const double);
  ^
In file included from /home/fradiavolo/Projects/GCD/geotools.cpp:1:0:
/home/fradiavolo/Projects/GCD/geotools.h:61:165: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const bool m_Correct_GeoCoordinate(const string sCoordinate = "",
const CoordinateType::CoordinateProperty t =
CoordinateType::CoordinateProperty::Undefined);
   
   
 ^
/home/fradiavolo/Projects/GCD/geotools.h:64:169: warning: type qualifiers
ignored on function return type [-Wignored-qualifiers]
 const double m_ConvertCordinate_2_Double(const string sGeoCoordinate,
const

[Bug c++/61668] Division returns an error in some cases

2014-07-02 Thread ketelbinkje at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

--- Comment #1 from Peter Ketel  ---
Created attachment 33044
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33044&action=edit
The next division returns the correct result


[Bug c++/61668] Division returns an error in some cases

2014-07-02 Thread ketelbinkje at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

Peter Ketel  changed:

   What|Removed |Added

   Severity|normal  |critical

--- Comment #4 from Peter Ketel  ---
(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.


[Bug c++/61668] Division returns an error in some cases

2014-07-04 Thread ketelbinkje at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668

--- Comment #8 from Peter Ketel  ---
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, sch...@linux-m68k.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61668
>
> --- Comment #7 from Andreas Schwab  ---
> Don't try to emulate decimal arithmetics with binary arithmetics.
>