ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 10 Aug 2016 14:03:46 +0200Testing if a result n is an Integer, for large n.https://ask.sagemath.org/question/34406/testing-if-a-result-n-is-an-integer-for-large-n/ I have a number x of size 2^160, and I perform the operation n = x*(x+1.5) and want to test if the result is an integer.
In python I would normally try, n.is_integer() or use an isinstance(), but this doesn't work in sage, I assume due to the fact sage integers are set up quite differently.
Upon scouring this site, I found someone recommend n is in ZZ, but this doesn't work (sage seems to loose accuracy at this level)
Example:
n = 2^160
n in ZZ
Result: False
The only (terribly inefficient) way I can get this to work is to call n.divisors() and if I get the error
"AttributeError: 'sage.rings.real_mpfr.RealNumber' object has no attribute 'divisors' "
I know it was indeed not an integer.
There must be a better way?
jbeatzWed, 10 Aug 2016 14:03:46 +0200https://ask.sagemath.org/question/34406/