🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #41627

??? multiply DOUBLEs --> wrong results ???

#41627
From: 0000-Admin 0000
Date: Thu, 29 Feb 1996 00:00
56 lines
2264 bytes
PLEASE HELP ME,
in C(++) programs (for DOS) I often use functions to
multiply DOUBLEs whith a factor, a DOUBLE too.
WHY isn't it the exactly result ????????????
The following program (linked with -lc -lm)
is a test to show you what I meen:
/******************************************/
#include <math.h>
#include <stdio.h>

int main(void)
{
double d=-1.0;
double dd=0.0;

for(int i=0;i<=20;i++)
	{
	dd=100.0*d;
	printf("%d. %lf %lf %d\n",i,d,dd,(int)dd);
	d+=0.1;
	}

return(0);
}
/******************************************/
This is the result of this program:
/******************************************/
0. -1.00000000000000 -100.00000000000000 -100
1. -0.90000000000000 -90.00000000000000 -90
2. -0.80000000000000 -80.00000000000000 -80
3. -0.70000000000000 -70.00000000000000 -70
4. -0.60000000000000 -60.00000000000001 -60
5. -0.50000000000000 -50.00000000000001 -50
6. -0.40000000000000 -40.00000000000001 -40
7. -0.30000000000000 -30.00000000000001 -30
8. -0.20000000000000 -20.00000000000001 -20
9. -0.10000000000000 -10.00000000000001 -10
10. 0.00000000000000 -0.00000000000001 0
11. 0.10000000000000 9.99999999999999 9
12. 0.20000000000000 19.99999999999999 19
13. 0.30000000000000 29.99999999999999 29
14. 0.40000000000000 39.99999999999999 39
15. 0.50000000000000 49.99999999999999 49
16. 0.60000000000000 59.99999999999999 59
17. 0.70000000000000 69.99999999999999 69
18. 0.80000000000000 79.99999999999999 79
19. 0.90000000000000 89.99999999999999 89
20. 1.00000000000000 99.99999999999997 99
/******************************************/
WHY are the values of "dd" like they above ????  
If you know or have an idea why this
happens, please send a mail to:

thozam@cs.tu-berlin.de

Thank you.
Technical Details
Message-ID: <4h405g$1d3@news.cs.tu-berlin.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,f187e8d834281194,start
X-Google-Attributes: gid11318c,public
From: "0000-Admin(0000)" <root>
Subject: ??? multiply DOUBLEs --> wrong results ???
Date: 1996/02/29
Message-ID: <4h405g$1d3@news.cs.tu-berlin.de>
X-Deja-AN: 141586794
content-type: text/plain
organization: Technical University of Berlin, Germany
x-url: file:/saale/ll
mime-version: 1.0
newsgroups: gnu.gcc.help
x-mailer: Mozilla 1.12 (X11; I; SunOS 5.3 sun4m)