remove PIC_ENABLE_FLOAT flag
This commit is contained in:
parent
5e13d35d10
commit
c2754509f2
|
@ -1,5 +1,7 @@
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_number_floor2(pic_state *pic)
|
pic_number_floor2(pic_state *pic)
|
||||||
{
|
{
|
||||||
|
|
|
@ -345,7 +345,6 @@ int xvfprintf(pic_state *pic, xFILE *stream, const char *fmt, va_list ap) {
|
||||||
ival = va_arg(ap, int);
|
ival = va_arg(ap, int);
|
||||||
cnt += print_int(pic, stream, ival, 10);
|
cnt += print_int(pic, stream, ival, 10);
|
||||||
break;
|
break;
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
#if PIC_ENABLE_LIBC
|
#if PIC_ENABLE_LIBC
|
||||||
case 'f': {
|
case 'f': {
|
||||||
char buf[100];
|
char buf[100];
|
||||||
|
@ -376,7 +375,6 @@ int xvfprintf(pic_state *pic, xFILE *stream, const char *fmt, va_list ap) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
case 's':
|
case 's':
|
||||||
sval = va_arg(ap, char*);
|
sval = va_arg(ap, char*);
|
||||||
|
|
|
@ -439,9 +439,7 @@ gc_mark_object(pic_state *pic, struct pic_object *obj)
|
||||||
}
|
}
|
||||||
case PIC_TT_NIL:
|
case PIC_TT_NIL:
|
||||||
case PIC_TT_BOOL:
|
case PIC_TT_BOOL:
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case PIC_TT_FLOAT:
|
case PIC_TT_FLOAT:
|
||||||
#endif
|
|
||||||
case PIC_TT_INT:
|
case PIC_TT_INT:
|
||||||
case PIC_TT_CHAR:
|
case PIC_TT_CHAR:
|
||||||
case PIC_TT_EOF:
|
case PIC_TT_EOF:
|
||||||
|
@ -679,9 +677,7 @@ gc_finalize_object(pic_state *pic, struct pic_object *obj)
|
||||||
}
|
}
|
||||||
case PIC_TT_NIL:
|
case PIC_TT_NIL:
|
||||||
case PIC_TT_BOOL:
|
case PIC_TT_BOOL:
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case PIC_TT_FLOAT:
|
case PIC_TT_FLOAT:
|
||||||
#endif
|
|
||||||
case PIC_TT_INT:
|
case PIC_TT_INT:
|
||||||
case PIC_TT_CHAR:
|
case PIC_TT_CHAR:
|
||||||
case PIC_TT_EOF:
|
case PIC_TT_EOF:
|
||||||
|
|
|
@ -205,10 +205,6 @@ strcpy(char *dst, const char *src)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
# include <math.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if PIC_ENABLE_STDIO
|
#if PIC_ENABLE_STDIO
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,9 +11,6 @@
|
||||||
/** enable word boxing */
|
/** enable word boxing */
|
||||||
/* #define PIC_WORD_BOXING 0 */
|
/* #define PIC_WORD_BOXING 0 */
|
||||||
|
|
||||||
/** enable floating point number support */
|
|
||||||
/* #define PIC_ENABLE_FLOAT 1 */
|
|
||||||
|
|
||||||
/** no dependency on libc */
|
/** no dependency on libc */
|
||||||
/* #define PIC_ENABLE_LIBC 1 */
|
/* #define PIC_ENABLE_LIBC 1 */
|
||||||
|
|
||||||
|
@ -68,10 +65,6 @@
|
||||||
# error cannot enable both PIC_NAN_BOXING and PIC_WORD_BOXING simultaneously
|
# error cannot enable both PIC_NAN_BOXING and PIC_WORD_BOXING simultaneously
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PIC_WORD_BOXING && PIC_ENABLE_FLOAT
|
|
||||||
# error cannot enable both PIC_WORD_BOXING and PIC_ENABLE_FLOAT simultaneously
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PIC_WORD_BOXING
|
#ifndef PIC_WORD_BOXING
|
||||||
# define PIC_WORD_BOXING 0
|
# define PIC_WORD_BOXING 0
|
||||||
#endif
|
#endif
|
||||||
|
@ -84,20 +77,10 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PIC_ENABLE_FLOAT
|
|
||||||
# if ! PIC_WORD_BOXING
|
|
||||||
# define PIC_ENABLE_FLOAT 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PIC_ENABLE_LIBC
|
#ifndef PIC_ENABLE_LIBC
|
||||||
# define PIC_ENABLE_LIBC 1
|
# define PIC_ENABLE_LIBC 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PIC_NAN_BOXING && defined(PIC_ENABLE_FLOAT) && ! PIC_ENABLE_FLOAT
|
|
||||||
# error cannot disable float support when nan boxing is on
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef PIC_ENABLE_STDIO
|
#ifndef PIC_ENABLE_STDIO
|
||||||
# define PIC_ENABLE_STDIO 1
|
# define PIC_ENABLE_STDIO 1
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,9 +20,7 @@ enum pic_vtype {
|
||||||
PIC_VTYPE_FALSE,
|
PIC_VTYPE_FALSE,
|
||||||
PIC_VTYPE_UNDEF,
|
PIC_VTYPE_UNDEF,
|
||||||
PIC_VTYPE_INVALID,
|
PIC_VTYPE_INVALID,
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
PIC_VTYPE_FLOAT,
|
PIC_VTYPE_FLOAT,
|
||||||
#endif
|
|
||||||
PIC_VTYPE_INT,
|
PIC_VTYPE_INT,
|
||||||
PIC_VTYPE_CHAR,
|
PIC_VTYPE_CHAR,
|
||||||
PIC_VTYPE_EOF,
|
PIC_VTYPE_EOF,
|
||||||
|
@ -116,9 +114,7 @@ typedef struct {
|
||||||
enum pic_vtype type;
|
enum pic_vtype type;
|
||||||
union {
|
union {
|
||||||
void *data;
|
void *data;
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
double f;
|
double f;
|
||||||
#endif
|
|
||||||
int i;
|
int i;
|
||||||
char c;
|
char c;
|
||||||
} u;
|
} u;
|
||||||
|
@ -128,9 +124,7 @@ typedef struct {
|
||||||
#define pic_vtype(v) ((v).type)
|
#define pic_vtype(v) ((v).type)
|
||||||
#define pic_init_value(v,vtype) ((v).type = (vtype), (v).u.data = NULL)
|
#define pic_init_value(v,vtype) ((v).type = (vtype), (v).u.data = NULL)
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
#define pic_float(v) ((v).u.f)
|
#define pic_float(v) ((v).u.f)
|
||||||
#endif
|
|
||||||
#define pic_int(v) ((v).u.i)
|
#define pic_int(v) ((v).u.i)
|
||||||
#define pic_char(v) ((v).u.c)
|
#define pic_char(v) ((v).u.c)
|
||||||
|
|
||||||
|
@ -140,9 +134,7 @@ enum pic_tt {
|
||||||
/* immediate */
|
/* immediate */
|
||||||
PIC_TT_NIL,
|
PIC_TT_NIL,
|
||||||
PIC_TT_BOOL,
|
PIC_TT_BOOL,
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
PIC_TT_FLOAT,
|
PIC_TT_FLOAT,
|
||||||
#endif
|
|
||||||
PIC_TT_INT,
|
PIC_TT_INT,
|
||||||
PIC_TT_CHAR,
|
PIC_TT_CHAR,
|
||||||
PIC_TT_EOF,
|
PIC_TT_EOF,
|
||||||
|
@ -218,21 +210,12 @@ PIC_INLINE const char *pic_type_repr(enum pic_tt);
|
||||||
pic_errorf(pic, "expected " #type ", but got ~s", v); \
|
pic_errorf(pic, "expected " #type ", but got ~s", v); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
PIC_INLINE bool
|
PIC_INLINE bool
|
||||||
pic_valid_int(double v)
|
pic_valid_int(double v)
|
||||||
{
|
{
|
||||||
return INT_MIN <= v && v <= INT_MAX;
|
return INT_MIN <= v && v <= INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
PIC_INLINE bool
|
|
||||||
pic_valid_int(int PIC_UNUSED(v))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PIC_INLINE pic_value pic_nil_value();
|
PIC_INLINE pic_value pic_nil_value();
|
||||||
PIC_INLINE pic_value pic_true_value();
|
PIC_INLINE pic_value pic_true_value();
|
||||||
PIC_INLINE pic_value pic_false_value();
|
PIC_INLINE pic_value pic_false_value();
|
||||||
|
@ -240,9 +223,7 @@ PIC_INLINE pic_value pic_bool_value(bool);
|
||||||
PIC_INLINE pic_value pic_undef_value();
|
PIC_INLINE pic_value pic_undef_value();
|
||||||
PIC_INLINE pic_value pic_invalid_value();
|
PIC_INLINE pic_value pic_invalid_value();
|
||||||
PIC_INLINE pic_value pic_obj_value(void *);
|
PIC_INLINE pic_value pic_obj_value(void *);
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
PIC_INLINE pic_value pic_float_value(double);
|
PIC_INLINE pic_value pic_float_value(double);
|
||||||
#endif
|
|
||||||
PIC_INLINE pic_value pic_int_value(int);
|
PIC_INLINE pic_value pic_int_value(int);
|
||||||
PIC_INLINE pic_value pic_size_value(size_t);
|
PIC_INLINE pic_value pic_size_value(size_t);
|
||||||
PIC_INLINE pic_value pic_char_value(char c);
|
PIC_INLINE pic_value pic_char_value(char c);
|
||||||
|
@ -264,10 +245,8 @@ pic_type(pic_value v)
|
||||||
return PIC_TT_UNDEF;
|
return PIC_TT_UNDEF;
|
||||||
case PIC_VTYPE_INVALID:
|
case PIC_VTYPE_INVALID:
|
||||||
return PIC_TT_INVALID;
|
return PIC_TT_INVALID;
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case PIC_VTYPE_FLOAT:
|
case PIC_VTYPE_FLOAT:
|
||||||
return PIC_TT_FLOAT;
|
return PIC_TT_FLOAT;
|
||||||
#endif
|
|
||||||
case PIC_VTYPE_INT:
|
case PIC_VTYPE_INT:
|
||||||
return PIC_TT_INT;
|
return PIC_TT_INT;
|
||||||
case PIC_VTYPE_CHAR:
|
case PIC_VTYPE_CHAR:
|
||||||
|
@ -289,10 +268,8 @@ pic_type_repr(enum pic_tt tt)
|
||||||
return "nil";
|
return "nil";
|
||||||
case PIC_TT_BOOL:
|
case PIC_TT_BOOL:
|
||||||
return "boolean";
|
return "boolean";
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case PIC_TT_FLOAT:
|
case PIC_TT_FLOAT:
|
||||||
return "float";
|
return "float";
|
||||||
#endif
|
|
||||||
case PIC_TT_INT:
|
case PIC_TT_INT:
|
||||||
return "int";
|
return "int";
|
||||||
case PIC_TT_SYMBOL:
|
case PIC_TT_SYMBOL:
|
||||||
|
@ -382,13 +359,11 @@ pic_bool_value(bool b)
|
||||||
PIC_INLINE pic_value
|
PIC_INLINE pic_value
|
||||||
pic_size_value(size_t s)
|
pic_size_value(size_t s)
|
||||||
{
|
{
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
if (sizeof(unsigned) < sizeof(size_t)) {
|
if (sizeof(unsigned) < sizeof(size_t)) {
|
||||||
if (s > (size_t)INT_MAX) {
|
if (s > (size_t)INT_MAX) {
|
||||||
return pic_float_value(s);
|
return pic_float_value(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return pic_int_value((int)s);
|
return pic_int_value((int)s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,8 +447,6 @@ pic_obj_value(void *ptr)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
|
|
||||||
PIC_INLINE pic_value
|
PIC_INLINE pic_value
|
||||||
pic_float_value(double f)
|
pic_float_value(double f)
|
||||||
{
|
{
|
||||||
|
@ -484,8 +457,6 @@ pic_float_value(double f)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PIC_INLINE pic_value
|
PIC_INLINE pic_value
|
||||||
pic_int_value(int i)
|
pic_int_value(int i)
|
||||||
{
|
{
|
||||||
|
@ -569,10 +540,8 @@ pic_eqv_p(pic_value x, pic_value y)
|
||||||
return true;
|
return true;
|
||||||
case PIC_TT_BOOL:
|
case PIC_TT_BOOL:
|
||||||
return pic_vtype(x) == pic_vtype(y);
|
return pic_vtype(x) == pic_vtype(y);
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case PIC_TT_FLOAT:
|
case PIC_TT_FLOAT:
|
||||||
return pic_float(x) == pic_float(y);
|
return pic_float(x) == pic_float(y);
|
||||||
#endif
|
|
||||||
case PIC_TT_INT:
|
case PIC_TT_INT:
|
||||||
return pic_int(x) == pic_int(y);
|
return pic_int(x) == pic_int(y);
|
||||||
default:
|
default:
|
||||||
|
@ -582,12 +551,11 @@ pic_eqv_p(pic_value x, pic_value y)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
#define pic_define_aop(name, op, guard) \
|
#define pic_define_aop(name, op, guard) \
|
||||||
PIC_INLINE pic_value \
|
PIC_INLINE pic_value \
|
||||||
name(pic_state *pic, pic_value a, pic_value b) \
|
name(pic_state *pic, pic_value a, pic_value b) \
|
||||||
{ \
|
{ \
|
||||||
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
||||||
double f; \
|
double f; \
|
||||||
if (pic_int_p(a) && pic_int_p(b)) { \
|
if (pic_int_p(a) && pic_int_p(b)) { \
|
||||||
f = (double)pic_int(a) op (double)pic_int(b); \
|
f = (double)pic_int(a) op (double)pic_int(b); \
|
||||||
|
@ -605,32 +573,17 @@ pic_eqv_p(pic_value x, pic_value y)
|
||||||
} \
|
} \
|
||||||
PIC_UNREACHABLE(); \
|
PIC_UNREACHABLE(); \
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
# define pic_define_aop(name, op, guard) \
|
|
||||||
PIC_INLINE pic_value \
|
|
||||||
name(pic_state *pic, pic_value a, pic_value b) \
|
|
||||||
{ \
|
|
||||||
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
|
||||||
if (pic_int_p(a) && pic_int_p(b)) { \
|
|
||||||
return pic_int_value(pic_int(a) op pic_int(b)); \
|
|
||||||
} else { \
|
|
||||||
pic_errorf(pic, #name ": non-number operand given"); \
|
|
||||||
} \
|
|
||||||
PIC_UNREACHABLE(); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pic_define_aop(pic_add, +, true)
|
pic_define_aop(pic_add, +, true)
|
||||||
pic_define_aop(pic_sub, -, true)
|
pic_define_aop(pic_sub, -, true)
|
||||||
pic_define_aop(pic_mul, *, true)
|
pic_define_aop(pic_mul, *, true)
|
||||||
pic_define_aop(pic_div, /, f == round(f))
|
pic_define_aop(pic_div, /, f == (int)f)
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
#define pic_define_cmp(name, op) \
|
#define pic_define_cmp(name, op) \
|
||||||
PIC_INLINE bool \
|
PIC_INLINE bool \
|
||||||
name(pic_state *pic, pic_value a, pic_value b) \
|
name(pic_state *pic, pic_value a, pic_value b) \
|
||||||
{ \
|
{ \
|
||||||
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
||||||
if (pic_int_p(a) && pic_int_p(b)) { \
|
if (pic_int_p(a) && pic_int_p(b)) { \
|
||||||
return pic_int(a) op pic_int(b); \
|
return pic_int(a) op pic_int(b); \
|
||||||
} else if (pic_float_p(a) && pic_float_p(b)) { \
|
} else if (pic_float_p(a) && pic_float_p(b)) { \
|
||||||
|
@ -644,20 +597,6 @@ pic_define_aop(pic_div, /, f == round(f))
|
||||||
} \
|
} \
|
||||||
PIC_UNREACHABLE(); \
|
PIC_UNREACHABLE(); \
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
# define pic_define_cmp(name, op) \
|
|
||||||
PIC_INLINE bool \
|
|
||||||
name(pic_state *pic, pic_value a, pic_value b) \
|
|
||||||
{ \
|
|
||||||
extern PIC_NORETURN void pic_errorf(pic_state *, const char *, ...); \
|
|
||||||
if (pic_int_p(a) && pic_int_p(b)) { \
|
|
||||||
return pic_int(a) op pic_int(b); \
|
|
||||||
} else { \
|
|
||||||
pic_errorf(pic, #name ": non-number operand given"); \
|
|
||||||
} \
|
|
||||||
PIC_UNREACHABLE(); \
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pic_define_cmp(pic_eq, ==)
|
pic_define_cmp(pic_eq, ==)
|
||||||
pic_define_cmp(pic_lt, <)
|
pic_define_cmp(pic_lt, <)
|
||||||
|
|
|
@ -11,11 +11,7 @@ pic_number_number_p(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &v);
|
pic_get_args(pic, "o", &v);
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
return pic_bool_value(pic_float_p(v) || pic_int_p(v));
|
return pic_bool_value(pic_float_p(v) || pic_int_p(v));
|
||||||
#else
|
|
||||||
return pic_bool_value(pic_int_p(v));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
@ -35,11 +31,7 @@ pic_number_inexact_p(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "o", &v);
|
pic_get_args(pic, "o", &v);
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
return pic_bool_value(pic_float_p(v));
|
return pic_bool_value(pic_float_p(v));
|
||||||
#else
|
|
||||||
return pic_false_value();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
@ -59,7 +51,7 @@ pic_number_exact(pic_state *pic)
|
||||||
|
|
||||||
pic_get_args(pic, "f", &f);
|
pic_get_args(pic, "f", &f);
|
||||||
|
|
||||||
return pic_int_value((int)(round(f)));
|
return pic_int_value((int)f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_CMP(op) \
|
#define DEFINE_CMP(op) \
|
||||||
|
@ -181,7 +173,6 @@ number_string(int val, int radix, int length, char *buffer) {
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_number_number_to_string(pic_state *pic)
|
pic_number_number_to_string(pic_state *pic)
|
||||||
{
|
{
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
double f;
|
double f;
|
||||||
bool e;
|
bool e;
|
||||||
int radix = 10;
|
int radix = 10;
|
||||||
|
@ -216,41 +207,11 @@ pic_number_number_to_string(pic_state *pic)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pic_obj_value(str);
|
return pic_obj_value(str);
|
||||||
#else
|
|
||||||
int f;
|
|
||||||
bool e;
|
|
||||||
int radix = 10;
|
|
||||||
pic_str *str;
|
|
||||||
size_t s;
|
|
||||||
char *buf;
|
|
||||||
int ival, ilen;
|
|
||||||
|
|
||||||
pic_get_args(pic, "i|i", &f, &e, &radix);
|
|
||||||
|
|
||||||
if (radix < 2 || radix > 36) {
|
|
||||||
pic_errorf(pic, "number->string: invalid radix %d (between 2 and 36, inclusive)", radix);
|
|
||||||
}
|
|
||||||
|
|
||||||
ival = f;
|
|
||||||
ilen = number_string_length(ival, radix);
|
|
||||||
s = ilen + 1;
|
|
||||||
|
|
||||||
buf = pic_malloc(pic, s);
|
|
||||||
|
|
||||||
number_string(ival, radix, ilen, buf);
|
|
||||||
|
|
||||||
str = pic_make_str(pic, buf, s - 1);
|
|
||||||
|
|
||||||
pic_free(pic, buf);
|
|
||||||
|
|
||||||
return pic_obj_value(str);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
pic_number_string_to_number(pic_state *pic)
|
pic_number_string_to_number(pic_state *pic)
|
||||||
{
|
{
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
const char *str;
|
const char *str;
|
||||||
int radix = 10;
|
int radix = 10;
|
||||||
long num;
|
long num;
|
||||||
|
@ -272,21 +233,6 @@ pic_number_string_to_number(pic_state *pic)
|
||||||
}
|
}
|
||||||
|
|
||||||
pic_errorf(pic, "invalid string given: %s", str);
|
pic_errorf(pic, "invalid string given: %s", str);
|
||||||
#else
|
|
||||||
const char *str;
|
|
||||||
int radix = 10;
|
|
||||||
long num;
|
|
||||||
char *eptr;
|
|
||||||
|
|
||||||
pic_get_args(pic, "z|i", &str, &radix);
|
|
||||||
|
|
||||||
num = strtol(str, &eptr, radix);
|
|
||||||
if (*eptr == '\0') {
|
|
||||||
return pic_int_value(num);
|
|
||||||
}
|
|
||||||
|
|
||||||
pic_errorf(pic, "invalid string given: %s", str);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -64,7 +64,6 @@ isdelim(int c)
|
||||||
return c == EOF || strchr("();,|\" \t\n\r", c) != NULL; /* ignores "#", "'" */
|
return c == EOF || strchr("();,|\" \t\n\r", c) != NULL; /* ignores "#", "'" */
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
static bool
|
static bool
|
||||||
strcaseeq(const char *s1, const char *s2)
|
strcaseeq(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +75,6 @@ strcaseeq(const char *s1, const char *s2)
|
||||||
}
|
}
|
||||||
return a == b;
|
return a == b;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
case_fold(pic_state *pic, int c)
|
case_fold(pic_state *pic, int c)
|
||||||
|
@ -271,7 +269,6 @@ read_unsigned(pic_state *pic, struct pic_port *port, int c)
|
||||||
u = read_uinteger(pic, port, c);
|
u = read_uinteger(pic, port, c);
|
||||||
|
|
||||||
switch (peek(pic, port)) {
|
switch (peek(pic, port)) {
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
#if PIC_ENABLE_LIBC
|
#if PIC_ENABLE_LIBC
|
||||||
case '.': {
|
case '.': {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
@ -312,7 +309,6 @@ read_unsigned(pic_state *pic, struct pic_port *port, int c)
|
||||||
}
|
}
|
||||||
return pic_float_value(f);
|
return pic_float_value(f);
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -346,15 +342,11 @@ read_number(pic_state *pic, struct pic_port *port, int c)
|
||||||
static pic_value
|
static pic_value
|
||||||
negate(pic_value n)
|
negate(pic_value n)
|
||||||
{
|
{
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
if (pic_int_p(n)) {
|
if (pic_int_p(n)) {
|
||||||
return pic_int_value(-pic_int(n));
|
return pic_int_value(-pic_int(n));
|
||||||
} else {
|
} else {
|
||||||
return pic_float_value(-pic_float(n));
|
return pic_float_value(-pic_float(n));
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
return pic_int_value(-pic_int(n));
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static pic_value
|
static pic_value
|
||||||
|
@ -367,14 +359,12 @@ read_minus(pic_state *pic, struct pic_port *port, int c)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sym = read_symbol(pic, port, c);
|
sym = read_symbol(pic, port, c);
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
if (strcaseeq(pic_symbol_name(pic, pic_sym_ptr(sym)), "-inf.0")) {
|
if (strcaseeq(pic_symbol_name(pic, pic_sym_ptr(sym)), "-inf.0")) {
|
||||||
return pic_float_value(-INFINITY);
|
return pic_float_value(-(1.0 / 0.0));
|
||||||
}
|
}
|
||||||
if (strcaseeq(pic_symbol_name(pic, pic_sym_ptr(sym)), "-nan.0")) {
|
if (strcaseeq(pic_symbol_name(pic, pic_sym_ptr(sym)), "-nan.0")) {
|
||||||
return pic_float_value(-NAN);
|
return pic_float_value(-(0.0 / 0.0));
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,14 +379,12 @@ read_plus(pic_state *pic, struct pic_port *port, int c)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sym = read_symbol(pic, port, c);
|
sym = read_symbol(pic, port, c);
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
if (strcaseeq(pic_symbol_name(pic, pic_sym_ptr(sym)), "+inf.0")) {
|
if (strcaseeq(pic_symbol_name(pic, pic_sym_ptr(sym)), "+inf.0")) {
|
||||||
return pic_float_value(INFINITY);
|
return pic_float_value(1.0 / 0.0);
|
||||||
}
|
}
|
||||||
if (strcaseeq(pic_symbol_name(pic, pic_sym_ptr(sym)), "+nan.0")) {
|
if (strcaseeq(pic_symbol_name(pic, pic_sym_ptr(sym)), "+nan.0")) {
|
||||||
return pic_float_value(NAN);
|
return pic_float_value(0.0 / 0.0);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ pic_init_features(pic_state *pic)
|
||||||
{
|
{
|
||||||
pic_add_feature(pic, "picrin");
|
pic_add_feature(pic, "picrin");
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
#if __STDC_IEC_559__
|
||||||
pic_add_feature(pic, "ieee-float");
|
pic_add_feature(pic, "ieee-float");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -316,11 +316,9 @@ pic_xvfformat(pic_state *pic, xFILE *file, const char *fmt, va_list ap)
|
||||||
case 'p':
|
case 'p':
|
||||||
xfprintf(pic, file, "%p", va_arg(ap, void *));
|
xfprintf(pic, file, "%p", va_arg(ap, void *));
|
||||||
break;
|
break;
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case 'f':
|
case 'f':
|
||||||
xfprintf(pic, file, "%f", va_arg(ap, double));
|
xfprintf(pic, file, "%f", va_arg(ap, double));
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '~':
|
case '~':
|
||||||
|
|
|
@ -103,7 +103,6 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
||||||
*p = GET_OPERAND(pic,i);
|
*p = GET_OPERAND(pic,i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case 'f': {
|
case 'f': {
|
||||||
double *f;
|
double *f;
|
||||||
pic_value v;
|
pic_value v;
|
||||||
|
@ -169,7 +168,6 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
case 'i': {
|
case 'i': {
|
||||||
int *k;
|
int *k;
|
||||||
pic_value v;
|
pic_value v;
|
||||||
|
@ -178,11 +176,9 @@ pic_get_args(pic_state *pic, const char *format, ...)
|
||||||
|
|
||||||
v = GET_OPERAND(pic, i);
|
v = GET_OPERAND(pic, i);
|
||||||
switch (pic_type(v)) {
|
switch (pic_type(v)) {
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case PIC_TT_FLOAT:
|
case PIC_TT_FLOAT:
|
||||||
*k = (int)pic_float(v);
|
*k = (int)pic_float(v);
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case PIC_TT_INT:
|
case PIC_TT_INT:
|
||||||
*k = pic_int(v);
|
*k = pic_int(v);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -101,19 +101,19 @@ write_str(pic_state *pic, pic_str *str, xFILE *file, int mode)
|
||||||
xfprintf(pic, file, "\"");
|
xfprintf(pic, file, "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
static void
|
static void
|
||||||
write_float(pic_state *pic, double f, xFILE *file)
|
write_float(pic_state *pic, double f, xFILE *file)
|
||||||
{
|
{
|
||||||
if (isnan(f)) {
|
if (f != f) {
|
||||||
xfprintf(pic, file, signbit(f) ? "-nan.0" : "+nan.0");
|
xfprintf(pic, file, "+nan.0");
|
||||||
} else if (isinf(f)) {
|
} else if (f == 1.0 / 0.0) {
|
||||||
xfprintf(pic, file, signbit(f) ? "-inf.0" : "+inf.0");
|
xfprintf(pic, file, "+inf.0");
|
||||||
|
} else if (f == -1.0 / 0.0) {
|
||||||
|
xfprintf(pic, file, "-inf.0");
|
||||||
} else {
|
} else {
|
||||||
xfprintf(pic, file, "%f", f);
|
xfprintf(pic, file, "%f", f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static void write_core(struct writer_control *p, pic_value);
|
static void write_core(struct writer_control *p, pic_value);
|
||||||
|
|
||||||
|
@ -291,11 +291,9 @@ write_core(struct writer_control *p, pic_value obj)
|
||||||
case PIC_TT_INT:
|
case PIC_TT_INT:
|
||||||
xfprintf(pic, file, "%d", pic_int(obj));
|
xfprintf(pic, file, "%d", pic_int(obj));
|
||||||
break;
|
break;
|
||||||
#if PIC_ENABLE_FLOAT
|
|
||||||
case PIC_TT_FLOAT:
|
case PIC_TT_FLOAT:
|
||||||
write_float(pic, pic_float(obj), file);
|
write_float(pic, pic_float(obj), file);
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case PIC_TT_SYMBOL:
|
case PIC_TT_SYMBOL:
|
||||||
xfprintf(pic, file, "%s", pic_symbol_name(pic, pic_sym_ptr(obj)));
|
xfprintf(pic, file, "%s", pic_symbol_name(pic, pic_sym_ptr(obj)));
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue