public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/4341: g++ built-in type double/float looses precision
@ 2001-09-18  1:43 nathan
  0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2001-09-18  1:43 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, srijohnson

Synopsis: g++ built-in type double/float looses precision

State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Tue Sep 18 01:43:34 2001
State-Changed-Why:
    not a bug. Please read http://www.acm.org/pubs/citations/journals/surveys/1991-23-1/p5-goldberg/
    and other information about why floating point numbers
    are not real numbers

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4341&database=gcc


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

* c++/4341: g++ built-in type double/float looses precision
@ 2001-09-17 19:16 srijohnson
  0 siblings, 0 replies; 2+ messages in thread
From: srijohnson @ 2001-09-17 19:16 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4341
>Category:       c++
>Synopsis:       g++ built-in type double/float looses precision
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 17 19:16:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Steve R. Johnson
>Release:        3.0.1 and below
>Organization:
>Environment:
RedHat Linux 7.0 + manual compiliations
>Description:
Variables of float or double types cannot be assigned to
some numbers properly.  For example:
double	db=36.3916;
It will actually assign to some arbitray infinite number like
36.3915999999999999999999999999999974327894329873428973421
2341897234198742389723418792341904231890423189034128904231
4389745378945392378943908757534278543343453490343456476...
I found this out by doing a cout with a precision of 15 of
the origional variable, except that it doesn't print out
the random garbage.  I didn't set the precision that high.

I wanted to perform an algorithm that will determine the
size of a double-type number.  This can be done by dividing
the number by the appropriate number of times by 10 to make
it .363916.  Then, in a loop, casts the db into a long
variable.
long lg=db  //lg=0 when db=0.363916
and moves the decimal to the right by 1 until lg==db;
lg=3		<	db=3.63916
lg=36		<	db=36.3916
lg=363		<	db=363.916
lg=3639		<	db=3639.16
lg=36391	<	db=36391.6
lg=363916	==	db=363916	//loop should terminate
But, this last condition will never occur because db is
really 363915999999999999999999898349340540954...
This type of algorithm will create an infinite loop.
Some numbers will do this in float too, but the same number
will not necessarily have this problem in both float and
double.
>How-To-Repeat:
If you wish for me to write a valid algorithm that is
effected by this bug, e-mail me and let me know.  Not all
floating point numbers have this bug.
>Fix:
None that I found yet.
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2001-09-18  1:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-18  1:43 c++/4341: g++ built-in type double/float looses precision nathan
  -- strict thread matches above, loose matches on Subject: below --
2001-09-17 19:16 srijohnson

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).