Francois, Never mind, I think I figured it out. Apparently, sage initializes .001 in MPFR using the fact that .001 = 1/1000. Using the appropriate set methods in MPFR fixes the issue. Attached is the code that makes Sage and MPFR agree.
Apparently, if I treat .001 as a float or double in MPFR the value MPFR returns does not agree with Sage. If I treat .001=1/1000 though, and initialize the rational with mpq, then take the logarithm the output will agree. This makes sense I guess. Perhaps .001 is not exactly representable in base 2 which causes the issue. Thanks, Rick On Thursday, October 2, 2014 8:44:50 PM UTC-4, François wrote: > > Don't really know at this stage, I am not familiar enough with that area > of sage to say whether or not your "a" will be defined on RR or a standard > numpy real or something else. > > Francois > > On Thu, 02 Oct 2014 17:35:49 ref...@uncg.edu <javascript:> wrote: > > Francois, > > > > Thank you for your reply. That's what I figured also, but where is the > > difference between the two codes? > > > > Thanks, > > > > Rick > > > > On Thursday, October 2, 2014 8:32:45 PM UTC-4, François wrote: > > > On Thu, 02 Oct 2014 17:28:15 ref...@uncg.edu <javascript:> wrote: > > > > When comparing the digits though, it appears that only around the > first > > > > > > 16 > > > > > > > or so digits are the same. > > > > > > That's were you can infer that something has been converted or left > > > as a double rather than a mpfr real number. > > > > > > Francois > > -- 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); mpq_t a; mpq_init(a); mpq_set_ui(a,1,1000); mpfr_set_q(x,a,MPFR_RNDN); mpfr_log(x,x,MPFR_RNDN); mpfr_out_str(stdout,10,0,x,MPFR_RNDN); printf("\n"); //This code checks the value using the fact that e^log(.001) = .001 mpfr_exp(x,x,MPFR_RNDN); mpfr_out_str(stdout,10,0,x,MPFR_RNDN); printf("\n"); printf("\n"); return 0; }