[sage-support] Re: int() on real numbers broken?

2014-03-25 Thread Zeda Thomas
Thanks much, that helps and I am pretty sure I understand what is going on! 

On Monday, March 24, 2014 10:49:18 AM UTC-4, Peter Bruin wrote:

 Hello, 

  I am working on a Z80 project and I needed 72 bits of precision for 64 
  elements of the form log2(1+2^-i) (so log2(3/2), log2(5/4),...). I 
  needed to convert these to hexadecimal, and it worked until I tried 
  the following for i=56: 
  int(256*log(1+2^-56,2)) 
  
  This returns 1, when in fact it should be 0. Actually, instead of 
  multiplying by 256, multiplying by 65536, or 600, or many other 
  numbers would also return the integer part as 1. 
  
  As a note, I used RealField(80) as my precision. 

 Typing log(1 + 2^-56, 2) gives the result as a symbolic expression, not 
 as an element of a real field.  Applying int() to this internally uses a 
 RealIntervalField with 53 bits of precision, which is not enough in this 
 case.  Here is a way to get the desired precision: 

 sage: x = RealField(80)(256*log(1+2^-56,2)) 
 sage: x 
 5.1254824061038682620123e-15 
 sage: int(x) 
 0 

 Peter 



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


[sage-support] int() on real numbers broken?

2014-03-24 Thread Zeda Thomas
I am working on a Z80 project and I needed 72 bits of precision for 64 elements 
of the form log2(1+2^-i) (so log2(3/2), log2(5/4),...). I needed to convert 
these to hexadecimal, and it worked until I tried the following for i=56:
int(256*log(1+2^-56,2))

This returns 1, when in fact it should be 0. Actually, instead of multiplying 
by 256, multiplying by 65536, or 600, or many other numbers would also return 
the integer part as 1.

As a note, I used RealField(80) as my precision.

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