Commit f78cb49d authored by Daniel Kochmański's avatar Daniel Kochmański

complex float: rename cl_lispunion member complex to gencomplex

Complex is a macro specified in complex.h for c99 to simplify using
_Complex type. This file also contains functions to work on complex
floats. To avoid conflicts we rename internal name complex to
gencomplex and update all references to it.
parent 6ecd2473
......@@ -350,8 +350,8 @@ cl_object_mark_proc(void *addr, struct GC_ms_entry *msp, struct GC_ms_entry *msl
MAYBE_MARK(o->ratio.den);
break;
case t_complex:
MAYBE_MARK(o->complex.real);
MAYBE_MARK(o->complex.imag);
MAYBE_MARK(o->gencomplex.real);
MAYBE_MARK(o->gencomplex.imag);
break;
case t_symbol:
MAYBE_MARK(o->symbol.hpack);
......
......@@ -59,8 +59,8 @@ _hash_eql(cl_hashkey h, cl_object x)
}
#endif
case t_complex:
h = _hash_eql(h, x->complex.real);
return _hash_eql(h, x->complex.imag);
h = _hash_eql(h, x->gencomplex.real);
return _hash_eql(h, x->gencomplex.imag);
case t_character:
return hash_word(h, ECL_CHAR_CODE(x));
#ifdef ECL_SSE2
......@@ -142,8 +142,8 @@ _hash_equal(int depth, cl_hashkey h, cl_object x)
}
# endif
case t_complex: {
h = _hash_equal(depth, h, x->complex.real);
return _hash_equal(depth, h, x->complex.imag);
h = _hash_equal(depth, h, x->gencomplex.real);
return _hash_equal(depth, h, x->gencomplex.imag);
}
#endif
default:
......@@ -201,8 +201,8 @@ _hash_equalp(int depth, cl_hashkey h, cl_object x)
h = _hash_equalp(0, h, x->ratio.num);
return _hash_equalp(0, h, x->ratio.den);
case t_complex:
h = _hash_equalp(0, h, x->complex.real);
return _hash_equalp(0, h, x->complex.imag);
h = _hash_equalp(0, h, x->gencomplex.real);
return _hash_equalp(0, h, x->gencomplex.imag);
case t_instance:
case t_hashtable:
/* FIXME! We should be more precise here! */
......
......@@ -434,7 +434,7 @@ cl_realpart(cl_object x)
#endif
break;
case t_complex:
x = x->complex.real;
x = x->gencomplex.real;
break;
default:
FEwrong_type_only_arg(@[realpart],x,@[number]);
......@@ -472,7 +472,7 @@ cl_imagpart(cl_object x)
break;
#endif
case t_complex:
x = x->complex.imag;
x = x->gencomplex.imag;
break;
default:
FEwrong_type_only_arg(@[imagpart],x,@[number]);
......
......@@ -618,8 +618,8 @@ ecl_make_complex(cl_object r, cl_object i)
}
c = ecl_alloc_object(t_complex);
c->complex.real = r;
c->complex.imag = i;
c->gencomplex.real = r;
c->gencomplex.imag = i;
return(c);
}
......
......@@ -81,8 +81,8 @@ ecl_abs_complex(cl_object x)
/* Compute sqrt(r*r + i*i) carefully to prevent overflow.
* Assume |i| >= |r|. Then sqrt(i*i + r*r) = |i|*sqrt(1 +(r/i)^2).
*/
cl_object r = ecl_abs(x->complex.real);
cl_object i = ecl_abs(x->complex.imag);
cl_object r = ecl_abs(x->gencomplex.real);
cl_object i = ecl_abs(x->gencomplex.imag);
int comparison;
comparison = ecl_number_compare(r, i);
if (comparison == 0) {
......
......@@ -30,7 +30,7 @@ ecl_conjugate_real(cl_object x)
static cl_object
ecl_conjugate_complex(cl_object x)
{
return ecl_make_complex(x->complex.real, ecl_negate(x->complex.imag));
return ecl_make_complex(x->gencomplex.real, ecl_negate(x->gencomplex.imag));
}
MATH_DEF_DISPATCH1_NE(conjugate, @[conjugate], @[number],
......
......@@ -57,8 +57,8 @@ ecl_cos_complex(cl_object x)
/* z = x + I y
cos(z) = cosh(I z) = cosh(-y + I x)
*/
cl_object dx = x->complex.real;
cl_object dy = x->complex.imag;
cl_object dx = x->gencomplex.real;
cl_object dy = x->gencomplex.imag;
cl_object a = ecl_times(ecl_cos(dx), ecl_cosh(dy));
cl_object b = ecl_times(ecl_negate(ecl_sin(dx)), ecl_sinh(dy));
return ecl_make_complex(a, b);
......
......@@ -60,8 +60,8 @@ ecl_cosh_complex(cl_object x)
= (exp(x)*(cos(y)+Isin(y))+exp(-x)*(cos(y)-Isin(y)))/2
= cosh(x)*cos(y) + Isinh(x)*sin(y);
*/
cl_object dx = x->complex.real;
cl_object dy = x->complex.imag;
cl_object dx = x->gencomplex.real;
cl_object dy = x->gencomplex.imag;
cl_object a = ecl_times(ecl_cosh(dx), ecl_cos(dy));
cl_object b = ecl_times(ecl_sinh(dx), ecl_sin(dy));
return ecl_make_complex(a, b);
......
......@@ -153,8 +153,8 @@ ecl_divide(cl_object x, cl_object y)
CASE_COMPLEX_RATIO;
CASE_COMPLEX_SINGLE_FLOAT;
CASE_COMPLEX_DOUBLE_FLOAT; COMPLEX_X: {
return ecl_make_complex(ecl_divide(x->complex.real, y),
ecl_divide(x->complex.imag, y));
return ecl_make_complex(ecl_divide(x->gencomplex.real, y),
ecl_divide(x->gencomplex.imag, y));
}
CASE_BIGNUM_COMPLEX;
CASE_RATIO_COMPLEX;
......@@ -162,11 +162,11 @@ ecl_divide(cl_object x, cl_object y)
CASE_DOUBLE_FLOAT_COMPLEX;
CASE_FIXNUM_COMPLEX {
COMPLEX_Y:
return complex_divide(x, ecl_make_fixnum(0), y->complex.real, y->complex.imag);
return complex_divide(x, ecl_make_fixnum(0), y->gencomplex.real, y->gencomplex.imag);
}
CASE_COMPLEX_COMPLEX {
return complex_divide(x->complex.real, x->complex.imag,
y->complex.real, y->complex.imag);
return complex_divide(x->gencomplex.real, x->gencomplex.imag,
y->gencomplex.real, y->gencomplex.imag);
}
CASE_UNKNOWN(@[/],x,y,@[number]);
}
......
......@@ -55,8 +55,8 @@ static cl_object
ecl_exp_complex(cl_object x)
{
cl_object y, y1;
y = x->complex.imag;
x = ecl_exp(x->complex.real);
y = x->gencomplex.imag;
x = ecl_exp(x->gencomplex.real);
y1 = ecl_cos(y);
y = ecl_sin(y);
y = ecl_make_complex(y1, y);
......
......@@ -76,8 +76,8 @@ expt_zero(cl_object x, cl_object y)
return longfloat_one;
#endif
case t_complex:
z = expt_zero((tx == t_complex)? x->complex.real : x,
(ty == t_complex)? y->complex.real : y);
z = expt_zero((tx == t_complex)? x->gencomplex.real : x,
(ty == t_complex)? y->gencomplex.real : y);
return ecl_make_complex(z, ecl_make_fixnum(0));
default:
/* We will never reach this */
......@@ -100,7 +100,7 @@ ecl_expt(cl_object x, cl_object y)
}
if (ecl_zerop(x)) {
z = x;
if (!ecl_plusp(ty==t_complex?y->complex.real:y))
if (!ecl_plusp(ty==t_complex?y->gencomplex.real:y))
z = ecl_divide(ecl_make_fixnum(1), z);
} else if (tx == t_singlefloat && ty == t_singlefloat && ecl_single_float(x) >= 0.0f) {
z = ecl_make_single_float(powf(ecl_single_float(x), ecl_single_float(y)));
......
......@@ -101,7 +101,7 @@ ecl_log1_long_float(cl_object x)
static cl_object
ecl_log1_complex(cl_object x)
{
return ecl_log1_complex_inner(x->complex.real, x->complex.imag);
return ecl_log1_complex_inner(x->gencomplex.real, x->gencomplex.imag);
}
MATH_DEF_DISPATCH1(log1, @[log], @[number],
......@@ -215,7 +215,7 @@ ecl_log1p_long_float(cl_object x)
static cl_object
ecl_log1p_complex(cl_object x)
{
return ecl_log1_complex_inner(ecl_one_plus(x->complex.real), x->complex.imag);
return ecl_log1_complex_inner(ecl_one_plus(x->gencomplex.real), x->gencomplex.imag);
}
MATH_DEF_DISPATCH1(log1p, @[si::log1p], @[number],
......
......@@ -150,8 +150,8 @@ ecl_minus(cl_object x, cl_object y)
CASE_COMPLEX_SINGLE_FLOAT;
CASE_COMPLEX_DOUBLE_FLOAT {
COMPLEX_X:
return ecl_make_complex(ecl_minus(x->complex.real, y),
x->complex.imag);
return ecl_make_complex(ecl_minus(x->gencomplex.real, y),
x->gencomplex.imag);
}
CASE_BIGNUM_COMPLEX;
CASE_RATIO_COMPLEX;
......@@ -159,12 +159,12 @@ ecl_minus(cl_object x, cl_object y)
CASE_DOUBLE_FLOAT_COMPLEX;
CASE_FIXNUM_COMPLEX {
COMPLEX_Y:
return ecl_make_complex(ecl_minus(x, y->complex.real),
ecl_negate(y->complex.imag));
return ecl_make_complex(ecl_minus(x, y->gencomplex.real),
ecl_negate(y->gencomplex.imag));
}
CASE_COMPLEX_COMPLEX {
cl_object z = ecl_minus(x->complex.real, y->complex.real);
cl_object z1 = ecl_minus(x->complex.imag, y->complex.imag);
cl_object z = ecl_minus(x->gencomplex.real, y->gencomplex.real);
cl_object z1 = ecl_minus(x->gencomplex.imag, y->gencomplex.imag);
return ecl_make_complex(z, z1);
}
CASE_UNKNOWN(@[-],x,y,@[number]);
......
......@@ -56,8 +56,8 @@ ecl_negate_long_float(cl_object x)
static cl_object
ecl_negate_complex(cl_object x)
{
return ecl_make_complex(ecl_negate(x->complex.real),
ecl_negate(x->complex.imag));
return ecl_make_complex(ecl_negate(x->gencomplex.real),
ecl_negate(x->gencomplex.imag));
}
MATH_DEF_DISPATCH1_NE(negate, @[-], @[number],
......
......@@ -168,21 +168,21 @@ ecl_number_equalp(cl_object x, cl_object y)
}
#endif
Y_COMPLEX:
if (!ecl_zerop(y->complex.imag))
if (!ecl_zerop(y->gencomplex.imag))
return 0;
return ecl_number_equalp(x, y->complex.real);
return ecl_number_equalp(x, y->gencomplex.real);
case t_complex:
switch (ecl_t_of(y)) {
case t_complex:
return (ecl_number_equalp(x->complex.real, y->complex.real) &&
ecl_number_equalp(x->complex.imag, y->complex.imag));
return (ecl_number_equalp(x->gencomplex.real, y->gencomplex.real) &&
ecl_number_equalp(x->gencomplex.imag, y->gencomplex.imag));
case t_fixnum: case t_bignum: case t_ratio:
case t_singlefloat: case t_doublefloat:
#ifdef ECL_LONG_FLOAT
case t_longfloat:
#endif
if (ecl_zerop(x->complex.imag))
return ecl_number_equalp(x->complex.real, y) != 0;
if (ecl_zerop(x->gencomplex.imag))
return ecl_number_equalp(x->gencomplex.real, y) != 0;
else
return 0;
default:
......
......@@ -59,8 +59,8 @@ ecl_one_minus_long_float(cl_object x)
static cl_object
ecl_one_minus_complex(cl_object x)
{
return ecl_make_complex(ecl_one_minus(x->complex.real),
x->complex.imag);
return ecl_make_complex(ecl_one_minus(x->gencomplex.real),
x->gencomplex.imag);
}
MATH_DEF_DISPATCH1_NE(one_minus, @[1-], @[number],
......
......@@ -59,8 +59,8 @@ ecl_one_plus_long_float(cl_object x)
static cl_object
ecl_one_plus_complex(cl_object x)
{
return ecl_make_complex(ecl_one_plus(x->complex.real),
x->complex.imag);
return ecl_make_complex(ecl_one_plus(x->gencomplex.real),
x->gencomplex.imag);
}
MATH_DEF_DISPATCH1_NE(one_plus, @[1+], @[number],
......
......@@ -155,12 +155,12 @@ ecl_plus(cl_object x, cl_object y)
CASE_DOUBLE_FLOAT_COMPLEX;
CASE_FIXNUM_COMPLEX {
COMPLEX_Y:
return ecl_make_complex(ecl_plus(x, y->complex.real),
y->complex.imag);
return ecl_make_complex(ecl_plus(x, y->gencomplex.real),
y->gencomplex.imag);
}
CASE_COMPLEX_COMPLEX {
cl_object z = ecl_plus(x->complex.real, y->complex.real);
cl_object z1 = ecl_plus(x->complex.imag, y->complex.imag);
cl_object z = ecl_plus(x->gencomplex.real, y->gencomplex.real);
cl_object z1 = ecl_plus(x->gencomplex.imag, y->gencomplex.imag);
return ecl_make_complex(z, z1);
}
CASE_UNKNOWN(@[+],x,y,@[number]);
......
......@@ -60,8 +60,8 @@ ecl_sin_complex(cl_object x)
z = x + I y
sin(z) = sinh(I z) = sinh(-y + I x)
*/
cl_object dx = x->complex.real;
cl_object dy = x->complex.imag;
cl_object dx = x->gencomplex.real;
cl_object dy = x->gencomplex.imag;
cl_object a = ecl_times(ecl_sin(dx), ecl_cosh(dy));
cl_object b = ecl_times(ecl_cos(dx), ecl_sinh(dy));
return ecl_make_complex(a, b);
......
......@@ -61,8 +61,8 @@ ecl_sinh_complex(cl_object x)
= (exp(x)*(cos(y)+Isin(y))-exp(-x)*(cos(y)-Isin(y)))/2
= sinh(x)*cos(y) + Icosh(x)*sin(y);
*/
cl_object dx = x->complex.real;
cl_object dy = x->complex.imag;
cl_object dx = x->gencomplex.real;
cl_object dy = x->gencomplex.imag;
cl_object a = ecl_times(ecl_sinh(dx), ecl_cos(dy));
cl_object b = ecl_times(ecl_cosh(dx), ecl_sin(dy));
return ecl_make_complex(a, b);
......
......@@ -157,14 +157,14 @@ ecl_times(cl_object x, cl_object y)
CASE_DOUBLE_FLOAT_COMPLEX;
CASE_FIXNUM_COMPLEX {
COMPLEX_Y:
return ecl_make_complex(ecl_times(x, y->complex.real),
ecl_times(x, y->complex.imag));
return ecl_make_complex(ecl_times(x, y->gencomplex.real),
ecl_times(x, y->gencomplex.imag));
}
CASE_COMPLEX_COMPLEX {
cl_object z11 = ecl_times(x->complex.real, y->complex.real);
cl_object z12 = ecl_times(x->complex.imag, y->complex.imag);
cl_object z21 = ecl_times(x->complex.imag, y->complex.real);
cl_object z22 = ecl_times(x->complex.real, y->complex.imag);
cl_object z11 = ecl_times(x->gencomplex.real, y->gencomplex.real);
cl_object z12 = ecl_times(x->gencomplex.imag, y->gencomplex.imag);
cl_object z21 = ecl_times(x->gencomplex.imag, y->gencomplex.real);
cl_object z22 = ecl_times(x->gencomplex.real, y->gencomplex.imag);
return ecl_make_complex(ecl_minus(z11, z12), ecl_plus(z21, z22));
}
CASE_UNKNOWN(@[*],x,y,@[number]);
......
......@@ -56,7 +56,7 @@ static int ecl_zerop_long_float(cl_object x)
static int
ecl_zerop_complex(cl_object x)
{
return ecl_zerop(x->complex.real) && ecl_zerop(x->complex.imag);
return ecl_zerop(x->gencomplex.real) && ecl_zerop(x->gencomplex.imag);
}
MATH_DEF_DISPATCH1_BOOL(zerop, @[zerop], @[number],
......
......@@ -293,8 +293,8 @@ ecl_eql(cl_object x, cl_object y)
FLOAT_EQL(ecl_long_float(x), ecl_long_float(y), long double);
#endif
case t_complex:
return (ecl_eql(x->complex.real, y->complex.real) &&
ecl_eql(x->complex.imag, y->complex.imag));
return (ecl_eql(x->gencomplex.real, y->gencomplex.real) &&
ecl_eql(x->gencomplex.imag, y->gencomplex.imag));
#ifdef ECL_SSE2
case t_sse_pack:
return !memcmp(x->sse.data.b8, y->sse.data.b8, 16);
......@@ -355,8 +355,8 @@ ecl_equal(register cl_object x, cl_object y)
}
#endif
case t_complex:
return (tx == ty) && ecl_eql(x->complex.real, y->complex.real) &&
ecl_eql(x->complex.imag, y->complex.imag);
return (tx == ty) && ecl_eql(x->gencomplex.real, y->gencomplex.real) &&
ecl_eql(x->gencomplex.imag, y->gencomplex.imag);
case t_character:
return (tx == ty) && (ECL_CHAR_CODE(x) == ECL_CHAR_CODE(y));
case t_base_string:
......
......@@ -101,9 +101,9 @@ static void
write_complex(cl_object x, cl_object stream)
{
writestr_stream("#C(", stream);
si_write_ugly_object(x->complex.real, stream);
si_write_ugly_object(x->gencomplex.real, stream);
ecl_write_char(' ', stream);
si_write_ugly_object(x->complex.imag, stream);
si_write_ugly_object(x->gencomplex.imag, stream);
ecl_write_char(')', stream);
}
......
......@@ -667,8 +667,8 @@ sharp_C_reader(cl_object in, cl_object c, cl_object d)
!Null(ECL_SYM_VAL(the_env, @'si::*sharp-eq-context*')))
{
x = ecl_alloc_object(t_complex);
x->complex.real = real;
x->complex.imag = imag;
x->gencomplex.real = real;
x->gencomplex.imag = imag;
} else {
x = ecl_make_complex(real, imag);
}
......@@ -1239,11 +1239,11 @@ do_patch_sharp(cl_object x, cl_object table)
}
break;
case t_complex: {
cl_object r = do_patch_sharp(x->complex.real, table);
cl_object i = do_patch_sharp(x->complex.imag, table);
if (r != x->complex.real || i != x->complex.imag) {
cl_object r = do_patch_sharp(x->gencomplex.real, table);
cl_object i = do_patch_sharp(x->gencomplex.imag, table);
if (r != x->gencomplex.real || i != x->gencomplex.imag) {
cl_object c = ecl_make_complex(r, i);
x->complex = c->complex;
x->gencomplex = c->gencomplex;
}
break;
}
......
......@@ -261,8 +261,8 @@ serialize_one(pool_t pool, cl_object what)
break;
}
case t_complex: {
buffer->complex.real = enqueue(pool, buffer->complex.real);
buffer->complex.imag = enqueue(pool, buffer->complex.imag);
buffer->gencomplex.real = enqueue(pool, buffer->gencomplex.real);
buffer->gencomplex.imag = enqueue(pool, buffer->gencomplex.imag);
break;
}
case t_hashtable:
......@@ -568,8 +568,8 @@ fixup(cl_object o, cl_object *o_list)
o->ratio.num = get_object(o->ratio.num, o_list);
break;
case t_complex:
o->complex.real = get_object(o->complex.real, o_list);
o->complex.imag = get_object(o->complex.imag, o_list);
o->gencomplex.real = get_object(o->gencomplex.real, o_list);
o->gencomplex.imag = get_object(o->gencomplex.imag, o_list);
break;
case t_hashtable:
fixup_hashtable(o, o_list);
......
......@@ -227,9 +227,6 @@ struct ecl_ratio {
cl_object num; /* numerator, must be an integer */
};
#ifdef _MSC_VER
#undef complex /* Otherwise we cannot do x->complex.real */
#endif
struct ecl_complex {
_ECL_HDR;
cl_object real; /* real part, must be a number */
......@@ -1055,7 +1052,7 @@ union cl_lispunion {
#ifdef ECL_LONG_FLOAT
struct ecl_long_float longfloat; /* long-float */
#endif
struct ecl_complex complex; /* complex number */
struct ecl_complex gencomplex; /* generic complex number */
#ifdef ECL_COMPLEX_FLOAT
struct ecl_csfloat csfloat; /* complex single float */
struct ecl_cdfloat cdfloat; /* complex double float */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment