mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-21 22:59:16 +02:00
Added square and expt as well as a macro to unbox numbers.
This commit is contained in:
parent
7747ca9da2
commit
1a2994d27b
2 changed files with 15 additions and 3 deletions
|
@ -103,6 +103,11 @@ object Cyc_global_set(void *thd, object *glo, object value);
|
|||
} \
|
||||
return_closcall1(data, cont, &i)
|
||||
|
||||
#define unbox_number(n) \
|
||||
((type_of(n) == integer_tag) ? \
|
||||
((integer_type *)n)->value : \
|
||||
((double_type *)n)->value)
|
||||
|
||||
/* Prototypes for primitive functions. */
|
||||
|
||||
extern object Cyc_global_variables;
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
floor-quotient
|
||||
floor-remainder
|
||||
floor/
|
||||
square
|
||||
expt
|
||||
call-with-current-continuation
|
||||
call/cc
|
||||
call-with-values
|
||||
|
@ -183,7 +185,6 @@
|
|||
; equal?
|
||||
; eqv?
|
||||
; exact-integer-sqrt
|
||||
; expt
|
||||
; foldl
|
||||
; foldr
|
||||
; get-output-bytevector
|
||||
|
@ -226,7 +227,6 @@
|
|||
; real?
|
||||
; record?
|
||||
; remainder
|
||||
; square
|
||||
; string->number
|
||||
; string->symbol
|
||||
; string->utf8
|
||||
|
@ -951,9 +951,16 @@
|
|||
(if (and (exact? n) (exact? m))
|
||||
(exact res)
|
||||
res)))
|
||||
;(define floor-remainder modulo)
|
||||
(define (floor-remainder n m)
|
||||
(- n (* m (floor-quotient n m))))
|
||||
(define (floor/ n m)
|
||||
(values (floor-quotient n m) (floor-remainder n m)))
|
||||
(define (square z) (* z z))
|
||||
(define-c expt
|
||||
"(void *data, int argc, closure _, object k, object z1, object z2)"
|
||||
" make_double(d, 0.0);
|
||||
Cyc_check_num(data, z1);
|
||||
Cyc_check_num(data, z2);
|
||||
d.value = pow( unbox_number(z1), unbox_number(z2) );
|
||||
return_closcall1(data, k, &d); ")
|
||||
))
|
||||
|
|
Loading…
Add table
Reference in a new issue