Add benz compile time hooks PIC_DOUBLE_TO_CSTRING and PIC_CSTRING_TO_DOUBLE

This commit is contained in:
Doug Currie 2016-01-08 23:06:14 -05:00
parent 4ef9394c0b
commit bfe1db8d16
3 changed files with 16 additions and 6 deletions

View File

@ -347,7 +347,7 @@ int xvfprintf(pic_state *pic, xFILE *stream, const char *fmt, va_list ap) {
break;
case 'f': {
char buf[64];
pic_dtoa(va_arg(ap, double), buf);
PIC_DOUBLE_TO_CSTRING(va_arg(ap, double), buf);
cnt += xfputs(pic, buf, stream);
break;
}

View File

@ -282,16 +282,16 @@ atof(const char *nptr)
#if PIC_ENABLE_STDIO
# include <stdio.h>
PIC_INLINE void
pic_dtoa(double dval, char *buf)
void
PIC_INLINE pic_dtoa(double dval, char *buf)
{
sprintf(buf, "%g", dval);
}
#else
PIC_INLINE void
pic_dtoa(double dval, char *buf)
void
PIC_INLINE pic_dtoa(double dval, char *buf)
{
# define fabs(x) ((x) >= 0 ? (x) : -(x))
long lval, tlval;
@ -339,6 +339,16 @@ pic_dtoa(double dval, char *buf)
#endif
#ifndef PIC_DOUBLE_TO_CSTRING
#define PIC_DOUBLE_TO_CSTRING pic_dtoa
#endif
void PIC_DOUBLE_TO_CSTRING(double, char *);
#ifndef PIC_CSTRING_TO_DOUBLE
#define PIC_CSTRING_TO_DOUBLE atof
#endif
double PIC_CSTRING_TO_DOUBLE(const char *);
#if defined(__cplusplus)
}
#endif

View File

@ -284,7 +284,7 @@ read_unsigned(pic_state *pic, struct pic_port *port, int c)
read_error(pic, "number too large",
pic_obj_value(pic_make_str(pic, (const char *)buf, ATOF_BUF_SIZE)));
buf[idx] = 0;
flt = atof(buf);
flt = PIC_CSTRING_TO_DOUBLE(buf);
if (dpe == 0 && pic_valid_int(flt))
return pic_int_value((int )flt);