Why does 'sage.rings.integer.Integer' not have "is_integer" method ??
sage: A=4
sage: A.is
A.is_idempotent A.is_nilpotent A.is_perfect_power A.is_prime
A.is_square A.is_zero
A.is_integral A.is_norm A.is_power
A.is_prime_power A.is_squarefree A.isqrt
A.is_irreducible A.is_one A.is_power_of
A.is_pseudoprime A.is_unit
while :
sage: A.is_
A.is_constant A.is_negative A.is_one
A.is_real A.is_square A.is_unit
A.is_idempotent A.is_nilpotent A.is_polynomial
A.is_relational A.is_symbol A.is_zero
****A.is_integer**** A.is_numeric A.is_positive
A.is_series A.is_terminating_series
In order to test of something is integer, is it safe to use isinstance ?
isinstance(A,sage.rings.integer.Integer)
I've missed something ?
Thanks
Laurent
>
> CONCLUSION:
>
> We already have four different meanings of the question "Is x an
> integer?". Since different meanings of the question require different
> answers, there is certainly not *one* single test for "bein an
> integer" in Sage.
Well. I didn't think to that. Thanks very much for your answer. I take
the third solution :)
In my case, I just want to make the difference between numbers like pi/2
and 90 in order to guess if the user is thinking about degrees or radian.
Laurent
You are guessing almost right.
In my case A is an user-given angle value that will be passed to
trigonometric functions.
I want to guess if the user gave radiant or degree.
My first test if
if "pi" in repr(A)
I cannot believe that someone will provide an angle with "pi" in degree.
In that case, I deal with A as radian.
Then my second test is to see if A is integer. One almost never deal
with integer radian. So if the A is integer, I will deal with it as degree.
I'm expecting some problems with degree values given as
pi/2 * 180/pi
(result of a conversion)
But well, up to now my function works :)
Thanks
Laurent
You'd want to make sure this behavior is well documented, otherwise it
could have unexpected behavior (e.g. what happens if you try to plot
it? Is 10.5 treated as a degree or radian?)
I'll be prudent since I am the user. It is not intended to be plotted.
What I'm doing is a class "Angle" that represent an angle and I'm
creating a method __add__ in such a way that
A=Angle(degree=45)
A+pi/2
will represent the angle 3pi/4
A=Angle(radian=pi)
A-180
will represent the angle 0.
But well, following your advise, I'm keeping an eye on the behavior of
that. I'll be mercyless against my function if I see a border effect.
Laurent