Newsgroups: comp.os.msdos.djgpp Subject: Re: Doubles won't see double!! From: Martin Ambuhl References: Organization: Nocturnal Aviation Message-ID: User-Agent: Xnews/5.04.25 X-Face: #PT?r&aN>ro*?:r AT h&l1(3WchlNz?9-y/wnr]CjPxdjd/*4lVC\*M+aZLO?E!2Q)]vD*M8oL(Zu2:VR17$t7-eVdNQH'!xp'5'NAP4$\fb"zAcf60HTC%S!<~xD}TFE76>a)IF-xa%$2at+D^;7~$mW^aDR)]bBmO``s wrote (18 Jul 2003) in news:KrkSa.23882$pK2 DOT 37447 AT news DOT indigo DOT ie / comp.os.msdos.djgpp: > Hello all, > > Just wondering this: > How can I perform maths on doubles, so that the result uses the > full potential of a double's decimal spaces? > > confused? ok, perhaps an example: > > double x,y,z; > x=22; > y=7; > z=x/y; > cout< > This will generally output something like: > 3.1425(or whatever) > however if I do the same sum on the windoze calculator: > 3.142857142957142857...................................you get the > picture > > so my question is this: How can I make MY doubles behave like > this? is there a library that i need to include? any suggestions? In C++ the , the ios_base classes have member functions precision() and width(); also provides setprecision and setw manipulators. Your C++ text should give you the information you need. Below is an example of accomplishing this in C: #include #include int main(void) { double x = 22, y = 7; long double xl = 22, yl = 7; float xf = 22, yf = 7; printf("double result: %.*g\n", DBL_DIG, x / y); printf("long double result: %.*Lg\n", LDBL_DIG, xl / yl); printf("float result: %.*g\n", FLT_DIG, xf / yf); return 0; } double result: 3.14285714285714 long double result: 3.14285714285714286 float result: 3.14286 -- Martin Ambuhl Returning soon to the Fourth Largest City in America