mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-18 21:29:18 +02:00
WIP - Cyc_sqrt
Working on an alternate implementation that supports complex numbers.
This commit is contained in:
parent
37b39693ed
commit
bcb0f86e8b
3 changed files with 36 additions and 2 deletions
|
@ -508,6 +508,8 @@ double round_to_nearest_even(double);
|
|||
void Cyc_exact(void *data, object cont, object z);
|
||||
object Cyc_exact_no_cps(void *data, object ptr, object z);
|
||||
|
||||
object Cyc_sqrt(void *data, object ptr, object z);
|
||||
|
||||
/**
|
||||
* Take Scheme object that is a number and return the number as a C type
|
||||
*/
|
||||
|
|
27
runtime.c
27
runtime.c
|
@ -8891,3 +8891,30 @@ object Cyc_exact_no_cps(void *data, object ptr, object z)
|
|||
}
|
||||
return obj_int2obj(i);
|
||||
}
|
||||
|
||||
object Cyc_sqrt(void *data, object ptr, object z)
|
||||
{
|
||||
double d;
|
||||
Cyc_check_num(data, z);
|
||||
if (obj_is_int(z)) {
|
||||
d = (obj_obj2int(z));
|
||||
} else if (type_of(z) == integer_tag) {
|
||||
d = (((integer_type *)z)->value);
|
||||
} else if (type_of(z) == bignum_tag) {
|
||||
d = (mp_get_double(&bignum_value(z)));
|
||||
} else {
|
||||
d = (((double_type *)z)->value);
|
||||
}
|
||||
|
||||
if (d >= 0) {
|
||||
d = sqrt(d);
|
||||
assign_double(ptr, d);
|
||||
} else {
|
||||
double dreal = 0.0;
|
||||
double dimag = sqrt(fabs(d));
|
||||
double complex c = dreal + (dimag * I);
|
||||
assign_complex_num(ptr, c);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
@ -1442,9 +1442,14 @@
|
|||
(values s r)))
|
||||
(define-c sqrt
|
||||
"(void *data, int argc, closure _, object k, object z)"
|
||||
" return_inexact_double_op(data, k, sqrt, z);"
|
||||
"
|
||||
common_type buffer;
|
||||
// TODO: can common type be brought forward into CPS as result like this? Need to double-check
|
||||
object result = Cyc_sqrt(data, &buffer, z);
|
||||
return_closcall1(data, k, result);
|
||||
"
|
||||
"(void *data, object ptr, object z)"
|
||||
" return_inexact_double_op_no_cps(data, ptr, sqrt, z);")
|
||||
" return Cyc_sqrt(data, ptr, z); ")
|
||||
(define-c exact-integer?
|
||||
"(void *data, int argc, closure _, object k, object num)"
|
||||
" if (obj_is_int(num) || (num != NULL && !is_value_type(num) &&
|
||||
|
|
Loading…
Add table
Reference in a new issue