Mail Archives: djgpp/2003/07/21/17:39:52
thx guys...i like the look of these "long doubles"
"Martin Ambuhl" <mambuhl AT earthlink DOT net> wrote in message
news:Xns93BE42C022A7mambuhlearthlinknet AT 207 DOT 217 DOT 77 DOT 26...
> "Noel O'Donnell" <nodger AT eircom DOT net> 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<<z;
> >
> > 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(); <iomanip> 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 <stdio.h>
> #include <float.h>
>
> 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
- Raw text -