Very basic comparison functionality for complex nums

This commit is contained in:
Justin Ethier 2018-05-10 13:20:17 -04:00
parent ea8a09f184
commit 9c64faa3df
2 changed files with 13 additions and 0 deletions

View file

@ -728,6 +728,9 @@ typedef struct {
/** Access a bignum's `mp_int` directly */
#define bignum_value(x) (((bignum_type *) x)->bn)
/** Access the complex number directly */
#define complex_num_value(x) (((complex_num_type *) x)->value)
/**
* This enumeration complements the comparison types from LibTomMath,
* and provides constants for each of the comparison operators.

View file

@ -1434,6 +1434,10 @@ int FUNC_OP(void *data, object x, object y) { \
result = Cyc_bignum_cmp(BN_CMP, x, tx, y, ty); \
} else if (tx == double_tag && ty == bignum_tag) { \
result = (double_value(x)) OP mp_get_double(&bignum_value(y)); \
} else if (tx == complex_num_tag && ty == complex_num_tag) { \
result = (complex_num_value(x)) == (complex_num_value(y)); \
} else if (tx == complex_num_tag && ty != complex_num_tag) { \
} else if (tx != complex_num_tag && ty == complex_num_tag) { \
} else { \
make_string(s, "Bad argument type"); \
make_pair(c1, y, NULL); \
@ -1511,6 +1515,12 @@ object FUNC_FAST_OP(void *data, object x, object y) { \
return Cyc_bignum_cmp(BN_CMP, x, tx, y, ty) ? boolean_t : boolean_f; \
} else if (tx == double_tag && ty == bignum_tag) { \
return (double_value(x)) OP mp_get_double(&bignum_value(x)) ? boolean_t : boolean_f; \
} else if (tx == complex_num_tag && ty == complex_num_tag) { \
return ((complex_num_value(x)) == (complex_num_value(y))) ? boolean_t : boolean_f; \
} else if (tx == complex_num_tag && ty != complex_num_tag) { \
return boolean_f; \
} else if (tx != complex_num_tag && ty == complex_num_tag) { \
return boolean_f; \
} else { \
goto bad_arg_type_error; \
} \