don't define number classifying procedures such as real? and complex? in C

This commit is contained in:
Yuichi Nishiwaki 2015-07-20 01:45:21 +09:00
parent ac10c3fcc1
commit a5317898cb
2 changed files with 15 additions and 33 deletions

View File

@ -9,7 +9,9 @@
ceiling
truncate
round
sqrt)
sqrt
nan?
infinite?)
(picrin macro)
(picrin string)
(scheme file))
@ -470,6 +472,16 @@
;; 6.2. Numbers
(define complex? number?)
(define real? number?)
(define rational? number?)
(define (integer? o)
(or (exact? o)
(and (inexact? o)
(not (nan? o))
(not (infinite? o))
(= o (floor o)))))
(define (exact-integer? x)
(and (exact? x)
(integer? x)))

View File

@ -58,7 +58,7 @@ number_string(int val, int radix, int length, char *buffer) {
}
static pic_value
pic_number_real_p(pic_state *pic)
pic_number_number_p(pic_state *pic)
{
pic_value v;
@ -71,32 +71,6 @@ pic_number_real_p(pic_state *pic)
#endif
}
static pic_value
pic_number_integer_p(pic_state *pic)
{
pic_value v;
pic_get_args(pic, "o", &v);
if (pic_int_p(v)) {
return pic_true_value();
}
#if PIC_ENABLE_FLOAT
if (pic_float_p(v)) {
double f = pic_float(v);
if (isinf(f)) {
return pic_false_value();
}
if (f == round(f)) {
return pic_true_value();
}
}
#endif
return pic_false_value();
}
static pic_value
pic_number_exact_p(pic_state *pic)
{
@ -451,11 +425,7 @@ pic_init_number(pic_state *pic)
{
size_t ai = pic_gc_arena_preserve(pic);
pic_defun(pic, "number?", pic_number_real_p);
pic_defun(pic, "complex?", pic_number_real_p);
pic_defun(pic, "real?", pic_number_real_p);
pic_defun(pic, "rational?", pic_number_real_p);
pic_defun(pic, "integer?", pic_number_integer_p);
pic_defun(pic, "number?", pic_number_number_p);
pic_gc_arena_restore(pic, ai);
pic_defun(pic, "exact?", pic_number_exact_p);