On Saturday, January 18, 2014 7:46:07 PM UTC-8, ref...@uncg.edu wrote: > > Before I begin, I'd like to thank you in advance for any help you may give. > > I'm trying to learn cython, and I'd like to use the RealNumber class. I'd > like to take a RealNumber as input, and compute the square of the > RealNumber, and return it. There is a catch though, I'd like to compute > this with more precision than the RealNumber I'm given. How can I change > the precision of the value returned? Here is the code snippet of what I'm > trying to describe: >
A sage RealNumber has little more hanging off it than just the mpfr. So I'd guess that if you create a real number with one precision and then stuff an mpfr inside with another, you might get unexpected results. You need to create a parent to hold the higher precision result first, i.e. R_higher_prec=RealField(val.prec()+100) In there you can now create new elements. That's where you should derive your "result" from. Setting the actual value can then probably be done via direct mpfr calls, but you may want to check that the extra hassle of that actually gets you any performance gain. For your other question, about the x=RR(0.0) in the inner loop: You are basically allocating the space for a real number there. You'll have to do that at some point. I suspect that your loop will not be faster than just RR=RealField(prec) [RR(i).log() for i in range(1,N+1)] The nice thing about cython is that often there is very little gain in doing it differently from the normal python solution. -- 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/groups/opt_out.