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)
|
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. */
|
/* Prototypes for primitive functions. */
|
||||||
|
|
||||||
extern object Cyc_global_variables;
|
extern object Cyc_global_variables;
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
floor-quotient
|
floor-quotient
|
||||||
floor-remainder
|
floor-remainder
|
||||||
floor/
|
floor/
|
||||||
|
square
|
||||||
|
expt
|
||||||
call-with-current-continuation
|
call-with-current-continuation
|
||||||
call/cc
|
call/cc
|
||||||
call-with-values
|
call-with-values
|
||||||
|
@ -183,7 +185,6 @@
|
||||||
; equal?
|
; equal?
|
||||||
; eqv?
|
; eqv?
|
||||||
; exact-integer-sqrt
|
; exact-integer-sqrt
|
||||||
; expt
|
|
||||||
; foldl
|
; foldl
|
||||||
; foldr
|
; foldr
|
||||||
; get-output-bytevector
|
; get-output-bytevector
|
||||||
|
@ -226,7 +227,6 @@
|
||||||
; real?
|
; real?
|
||||||
; record?
|
; record?
|
||||||
; remainder
|
; remainder
|
||||||
; square
|
|
||||||
; string->number
|
; string->number
|
||||||
; string->symbol
|
; string->symbol
|
||||||
; string->utf8
|
; string->utf8
|
||||||
|
@ -951,9 +951,16 @@
|
||||||
(if (and (exact? n) (exact? m))
|
(if (and (exact? n) (exact? m))
|
||||||
(exact res)
|
(exact res)
|
||||||
res)))
|
res)))
|
||||||
;(define floor-remainder modulo)
|
|
||||||
(define (floor-remainder n m)
|
(define (floor-remainder n m)
|
||||||
(- n (* m (floor-quotient n m))))
|
(- n (* m (floor-quotient n m))))
|
||||||
(define (floor/ n m)
|
(define (floor/ n m)
|
||||||
(values (floor-quotient n m) (floor-remainder 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