00001 #include "multiprec.h" 00002 00020 inline int 00021 ymp_compare_abs(mp_cref_t lhs, mp_cref_t rhs) 00022 { 00023 if (lhs->used > rhs->used) 00024 { 00025 return 1; 00026 } 00027 else if (lhs->used < rhs->used) 00028 { 00029 return -1; 00030 } 00031 else 00032 { 00033 size_t i; 00034 for (i=lhs->used; i-- > 0; ) 00035 { 00036 if (lhs->digits[i] > rhs->digits[i]) return 1; 00037 else if (lhs->digits[i] < rhs->digits[i]) return -1; 00038 } 00039 } 00040 return 0; 00041 } 00042 00043 00053 int 00054 ymp_compare(mp_cref_t lhs, mp_cref_t rhs) 00055 { 00056 if (lhs->sign != rhs->sign) 00057 return rhs->sign - lhs->sign; 00058 else if (lhs->sign) 00059 return ymp_compare_abs(rhs, lhs); 00060 else 00061 return ymp_compare_abs(lhs, rhs); 00062 } 00063 00073 int 00074 ymp_compare_digit(mp_cref_t lhs, digit_t rhs) 00075 { 00076 if (lhs->sign) return -1; 00077 00078 if (lhs->used > 1) return 1; 00079 else if (lhs->used == 1) 00080 { 00081 if (lhs->digits[0] > rhs) return 1; 00082 else if (lhs->digits[0] < rhs) return -1; 00083 else return 0; 00084 } 00085 else return -(rhs!=0); 00086 } 00087 00088 00094 int 00095 ymp_is_zero(mp_cref_t self) 00096 { 00097 return !self || !self->used || (self->used==1 && !self->digits[0]); 00098 } 00099 00105 int 00106 ymp_is_even(mp_cref_t self) 00107 { 00108 return !self || !self->used || !(self->digits[0] & 0x01); 00109 } 00110