Dear All,

I appreciate any help that I can get with this question.  Thank you in 
advance.

I've been converting some of my algorithms that wrote using Sage into C.  I 
noticed that it appears that MPFR and Sage do not match when taking 
logarithms of certain values at arbitrary precision.  As an example, 
consider the following lines in Sage:

RR = RealField(1000)
x = RR(.001)
a= log(x)

When I do this, Sage says that:

a=-6.90775527898213705205397436405309262280330446588631892809998370290271782903205744070799161526879489502590335212685874590022857639524842026999886210729634506844872162497666404253139968447869959558518051592689613319788653849009866686309465966023963100242321272982309546514680294481817443885821320066631

When comparing to MPFR, if I run the attached code in the command line 
(that I believe does the same thing as above) using

gcc -Wall -W -Werror logs.c -o logs -lm -lmpfr -lgmp
./logs

The output of the program is:

-6.90775527898213703123729265233140770652732943274746853066220338998698620110531195719818129463092278351819792580811173018723242118875465470783068399942176413540835294300881628169088830077469356711717015036454074809229573906590734510694077140442685761387606643232451253919766892057408972733372702726501595

When comparing the digits though, it appears that only around the first 16 
or so digits are the same.  To see this, I put the value that Sage returns 
against the value that MPFR returns on top of each other and highlight 
where the digits start to disagree in red:

-6.9077552789821370
5205397436405309262280330446588631892809998370290271782903205744070799161526879489502590335212685874590022857639524842026999886210729634506844872162497666404253139968447869959558518051592689613319788653849009866686309465966023963100242321272982309546514680294481817443885821320066631

-6.9077552789821370
3123729265233140770652732943274746853066220338998698620110531195719818129463092278351819792580811173018723242118875465470783068399942176413540835294300881628169088830077469356711717015036454074809229573906590734510694077140442685761387606643232451253919766892057408972733372702726501595

Does anyone see why the values would be so much different?  I thought that 
Sage called MPFR to find these values.

Thanks,

Rick

P.S. I'm using Sage version 5.12, gcc version 4.7.3, and as far as I know 
I'm using the newest version of MPFR.


-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.
/*
 * logs.c
 *
 *      Author: Ricky Farr
 */

#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#include <mpfr.h>

int main(){
	mpfr_t x;
	mpfr_init2(x,1000);
	mpfr_set_d(x,.001,MPFR_RNDN);
	mpfr_log(x,x,MPFR_RNDN);
	mpfr_out_str(stdout,10,0,x,MPFR_RNDN);
	printf("\n");
	return 0;
}

Reply via email to