From 9c64faa3dfcbf62341e4d510d6ef3d665076f693 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 10 May 2018 13:20:17 -0400 Subject: [PATCH] Very basic comparison functionality for complex nums --- include/cyclone/types.h | 3 +++ runtime.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/cyclone/types.h b/include/cyclone/types.h index f08d2d4b..22696589 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -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. diff --git a/runtime.c b/runtime.c index b5f2b06b..05337de2 100644 --- a/runtime.c +++ b/runtime.c @@ -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; \ } \