Re: Getting greatest decimal accuracy out of G_PI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 3 Feb 2007 01:46:08 +0100David Nečas (Yeti) <yeti@xxxxxxxxxxxxxxx> wrote:
>On Fri, Feb 02, 2007 at 04:14:09PM -0800, Sergei Steshenko wrote:>> >> You can still use explicit cast, i.e.>> >> ((long double)G_PI)>> >> , can't you?>>If you can demonstrate a program that gets the value of G_PI>to a long double with the full precision, please enlighten>me.>Yeti
I'll post this in case anyone in the future searches the archivesfor an answer.
This works, but it needs the mpfr library and gmp fromhttp://www.mpfr.org/mpfr-current/
/*  gcc -o mfpr-test mfpr-test.c  `pkg-config --cflags --libs gtk+-2.0` -lgmp -lmpfr */
#include <stdio.h>#include <gmp.h>#include <mpfr.h>#include <gtk/gtk.h>
int main (void){   mpfr_t pi,g_pi;
  mpfr_init2 (pi, 200);  mpfr_init2 (g_pi, 200);     mpfr_set_ld(pi, 3.1415926535897932384626433832795028841971693993751, GMP_RNDN);  mpfr_set_ld(g_pi, G_PI, GMP_RNDN);    g_print("PI is ");  mpfr_out_str (stdout, 10, 0, pi, GMP_RNDN);  g_print("\n");  mpfr_clear (pi);
  g_print("G_PI is ");  mpfr_out_str (stdout, 10, 0, g_pi , GMP_RNDN);  g_print("\n");  mpfr_clear (g_pi);
  return 0;}
__END__
Output:PI is 3.1415926535897931159979634685441851615905761718750000000000000G_PI is 3.1415926535897931159979634685441851615905761718750000000000000


However, to be fair to Tor's comments, I did a rudimentary calculation using the15 decimal point version of G_PI ( which is available to the standard libraries).and found the resolutions on the surface of the earth and the moon, to bepretty good  ( from the center of the earth asssuming 0.0000000000000001 rad angular resolution )earth res:  0.00000000035 metersmoon res: 0.00000003835 meters
So unless I need to find a quarter on Jupiter, I should be OK. :-)
One other point though, g_print won't accept the mpfr_t as a long double,so the "%Lf" format won't work.
zentara

-- I'm not really a human, but I play one on earth.http://zentara.net/japh.html_______________________________________________gtk-list mailing listgtk-list@xxxxxxxxxxxxx://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux